repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/dataset/_partial_dataset.py | stable_nalu/dataset/_partial_dataset.py |
import torch
class PartialDataset(torch.utils.data.Dataset):
def __init__(self, full_dataset, offset, length):
super().__init__()
self.full_dataset = full_dataset
self.offset = offset
self.length = length
def __len__(self):
return self.length
def __getitem__(self... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/dataset/_simple_function_abstact.py | stable_nalu/dataset/_simple_function_abstact.py |
import itertools
import math
import numpy as np
import torch
import torch.utils.data
from ._dataloader import FastDataLoader
class ARITHMETIC_FUNCTIONS_STRINGIY:
@staticmethod
def add(*subsets):
return ' + '.join(map(str, subsets))
@staticmethod
def sub(a, b, *extra):
return f'{a} - ... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/dataset/number_translation.py | stable_nalu/dataset/number_translation.py |
import os.path as path
import numpy as np
import torch
import torch.utils.data
import torchvision
from ._dataloader import DataLoaderCudaWrapper
id2token = [
'<pad>',
'and',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine',
'ten',
'eleven',
... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/network/sequential_mnist.py | stable_nalu/network/sequential_mnist.py |
import torch
from ..abstract import ExtendedTorchModule
from ..layer import GeneralizedLayer, GeneralizedCell
from .regression_mnist import RegressionMnistNetwork
class SequentialMnistNetwork(ExtendedTorchModule):
UNIT_NAMES = GeneralizedCell.UNIT_NAMES
def __init__(self, unit_name, output_size, writer=None,... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/network/sequential_svhn.py | stable_nalu/network/sequential_svhn.py |
import torch
import torchvision
from ..abstract import ExtendedTorchModule
from ..layer import GeneralizedLayer, GeneralizedCell
class SequentialSvhnNetwork(ExtendedTorchModule):
UNIT_NAMES = GeneralizedCell.UNIT_NAMES
def __init__(self, unit_name, output_size, writer=None,
svhn_outputs=1, r... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/network/simple_function_static_test.py | stable_nalu/network/simple_function_static_test.py |
from nose.tools import *
import torch
import numpy as np
from stable_nalu.dataset import SimpleFunctionStaticDataset
from stable_nalu.network import SimpleFunctionStaticNetwork
def test_linear_solves_add():
dataset = SimpleFunctionStaticDataset(operation='add', seed=0)
dataset_test = dataset.fork(input_rang... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/network/simple_function_static.py | stable_nalu/network/simple_function_static.py |
import torch
from ..abstract import ExtendedTorchModule
from ..layer import GeneralizedLayer, BasicLayer
class SimpleFunctionStaticNetwork(ExtendedTorchModule):
UNIT_NAMES = GeneralizedLayer.UNIT_NAMES
def __init__(self, unit_name, input_size=100, hidden_size=2, writer=None, first_layer=None, nac_mul='none',... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/network/__init__.py | stable_nalu/network/__init__.py |
from .simple_function_static import SimpleFunctionStaticNetwork
from .simple_function_recurrent import SimpleFunctionRecurrentNetwork
from .sequential_svhn import SequentialSvhnNetwork
from .sequential_mnist import SequentialMnistNetwork
from .regression_mnist import RegressionMnistNetwork
from .number_translation imp... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/network/simple_function_recurrent.py | stable_nalu/network/simple_function_recurrent.py |
import torch
from ..abstract import ExtendedTorchModule
from ..layer import GeneralizedLayer, GeneralizedCell
class SimpleFunctionRecurrentNetwork(ExtendedTorchModule):
UNIT_NAMES = GeneralizedCell.UNIT_NAMES
def __init__(self, unit_name, input_size=10, writer=None, **kwargs):
super().__init__('netwo... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/network/regression_mnist.py | stable_nalu/network/regression_mnist.py |
import torch
from ..abstract import ExtendedTorchModule
from ..layer import GeneralizedLayer, GeneralizedCell
# Copied from https://github.com/pytorch/examples/blob/master/mnist/main.py, just added a
# reset_parameters method and changed final layer to have one output.
class RegressionMnistNetwork(ExtendedTorchModul... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/network/number_translation.py | stable_nalu/network/number_translation.py |
import torch
from ..abstract import ExtendedTorchModule
from ..layer import GeneralizedLayer, GeneralizedCell
class NumberTranslationNetwork(ExtendedTorchModule):
UNIT_NAMES = GeneralizedCell.UNIT_NAMES
def __init__(self, unit_name,
embedding_size=2, # 1 for the number, 1 for the gate ?
... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/nac_weight_test.py | stable_nalu/functional/nac_weight_test.py |
import numpy as np
import torch
from stable_nalu.functional import nac_weight
def test_nac_weight_calculates_backward_correctly():
w_hat = torch.randn(100, 2, requires_grad=True, dtype=torch.float64)
m_hat = torch.randn(100, 2, requires_grad=True, dtype=torch.float64)
torch.autograd.gradcheck(
l... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/sparsity_error.py | stable_nalu/functional/sparsity_error.py |
import torch
def sparsity_error(W):
W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W)))
return torch.max(W_error)
| python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/batch_linear.py | stable_nalu/functional/batch_linear.py |
import torch
def batch_linear(x, W, b=None):
"""Computes y_i = x_i W_i + b_i where i is each observation index.
This is similar to `torch.nn.functional.linear`, but a version that
supports a different W for each observation.
x: has shape [obs, in_dims]
W: has shape [obs, out_dims, in_dims]
b... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/mnac.py | stable_nalu/functional/mnac.py |
import torch
def mnac(x, W, mode='prod'):
out_size, in_size = W.size()
x = x.view(x.size()[0], in_size, 1)
W = W.t().view(1, in_size, out_size)
if mode == 'prod':
return torch.prod(x * W + 1 - W, -2)
elif mode == 'exp-log':
return torch.exp(torch.sum(torch.log(x * W + 1 - W), -2))... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/gumbel.py | stable_nalu/functional/gumbel.py |
import torch
def sample_gumbel(placeholder, eps=1e-10, reuse=False):
"""Samples Gumbel(0, 1) values into the placeholder"""
# Uniform sample between [eps, 1)
if reuse:
uniform = placeholder
else:
uniform = placeholder.uniform_(eps, 1)
# Inverse transform
g = -torch.log(-torch... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/regualizer_nau_z.py | stable_nalu/functional/regualizer_nau_z.py |
import torch
class RegualizerNAUZ:
def __init__(self, zero=False):
self.zero = zero
self.stored_inputs = []
def __call__(self, W):
if self.zero:
return 0
x_mean = torch.mean(
torch.cat(self.stored_inputs, dim=0),
dim=0, keepdim=True
... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/__init__.py | stable_nalu/functional/__init__.py |
from .gated_choice import gated_choice
from .nac_weight import nac_weight
from .gumbel import sample_gumbel_softmax, sample_gumbel_max
from .batch_linear import batch_linear
from .mnac import mnac
from .regualizer import Regualizer
from .regualizer_nmu_z import RegualizerNMUZ
from .regualizer_nau_z import RegualizerNA... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/gated_choice_test.py | stable_nalu/functional/gated_choice_test.py |
import numpy as np
import torch
from stable_nalu.functional.gated_choice import GatedChoiceNormal
def test_gated_choice_calculates_backward_correctly_indpendent():
g_hat = torch.randn(20, 2, requires_grad=True, dtype=torch.float64)
a_hat = torch.randn(20, 2, requires_grad=True, dtype=torch.float64)
m_hat... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/regualizer.py | stable_nalu/functional/regualizer.py |
import torch
class Regualizer:
def __init__(self, support='nac', type='bias', shape='squared', zero=False, zero_epsilon=0):
super()
self.zero_epsilon = 0
if zero:
self.fn = self._zero
else:
identifier = '_'.join(['', support, type, shape])
self.... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/nac_weight.py | stable_nalu/functional/nac_weight.py |
import torch
class NACWeight(torch.autograd.Function):
r"""Implements the NAC weight operator
w = tanh(\hat{w}) * sigmoid(\hat{m})
"""
@staticmethod
def forward(ctx, w_hat, m_hat):
tanh_w_hat = torch.tanh(w_hat)
sigmoid_m_hat = torch.sigmoid(m_hat)
ctx.save_for_backward(t... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/regualizer_nmu_z.py | stable_nalu/functional/regualizer_nmu_z.py |
import torch
class RegualizerNMUZ:
def __init__(self, zero=False):
self.zero = zero
self.stored_inputs = []
def __call__(self, W):
if self.zero:
return 0
x_mean = torch.mean(
torch.cat(self.stored_inputs, dim=0),
dim=0, keepdim=True
... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/stable_nalu/functional/gated_choice.py | stable_nalu/functional/gated_choice.py |
import torch
class GatedChoiceNormal(torch.autograd.Function):
@staticmethod
def forward(ctx, g, v):
ctx.save_for_backward(g, v)
return g * v
@staticmethod
def backward(ctx, grad_output):
g, v = ctx.saved_tensors
return (
grad_output * v,
grad_... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/export/sequential_mnist.py | export/sequential_mnist.py |
import os
import csv
import sys
import argparse
import stable_nalu
# Parse arguments
parser = argparse.ArgumentParser(description='Export results from simple function task')
parser.add_argument('--tensorboard-dir',
action='store',
type=str,
help='Specify th... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
AndreasMadsen/stable-nalu | https://github.com/AndreasMadsen/stable-nalu/blob/b3296ace137ffa4854edeef3759f1578b7650210/export/simple_function_static.py | export/simple_function_static.py |
import os
import csv
import sys
import argparse
import stable_nalu
# Parse arguments
parser = argparse.ArgumentParser(description='Export results from simple function task')
parser.add_argument('--tensorboard-dir',
action='store',
type=str,
help='Specify th... | python | MIT | b3296ace137ffa4854edeef3759f1578b7650210 | 2026-01-05T07:14:37.360899Z | false |
SeargeDP/ComfyUI_Searge_LLM | https://github.com/SeargeDP/ComfyUI_Searge_LLM/blob/241d4c8d8243515cf19cab2d2ee051745fc5f592/Searge_LLM_Node.py | Searge_LLM_Node.py | import importlib
import os
import folder_paths
GLOBAL_MODELS_DIR = os.path.join(folder_paths.models_dir, "llm_gguf")
WEB_DIRECTORY = "./web/assets/js"
DEFAULT_INSTRUCTIONS = 'Generate a prompt from "{prompt}"'
try:
Llama = importlib.import_module("llama_cpp_cuda").Llama
except ImportError:
Llama = importli... | python | MIT | 241d4c8d8243515cf19cab2d2ee051745fc5f592 | 2026-01-05T07:14:41.725674Z | false |
SeargeDP/ComfyUI_Searge_LLM | https://github.com/SeargeDP/ComfyUI_Searge_LLM/blob/241d4c8d8243515cf19cab2d2ee051745fc5f592/__init__.py | __init__.py | from .Searge_LLM_Node import *
| python | MIT | 241d4c8d8243515cf19cab2d2ee051745fc5f592 | 2026-01-05T07:14:41.725674Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/data_encapsulation.py | code/data_collection/cc/cc_net/data_encapsulation.py | import json
import os
from glob import glob
import gzip
import argparse
parser=argparse.ArgumentParser()
parser.add_argument(
"--input_dir",
type=str,
)
parser.add_argument(
"--output_dir",
type=str,
)
parser.add_argument(
'--keep_bucket',
nargs="+",
type=str,
)
args=parser.parse_args()
p... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/setup.py | code/data_collection/cc/cc_net/setup.py | # Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
from pathlib import Path
from setuptools import setup # type: ignore
setup(
name="cc_net",
version="1.0.0",
pa... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/tests/test_transformer.py | code/data_collection/cc/cc_net/tests/test_transformer.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import inspect
import pickle
from pathlib import Path
import pytest
from cc_net import dedup, jsonql, perplexity, split_by_lang, tokenizer... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/tests/test_jsonql.py | code/data_collection/cc/cc_net/tests/test_jsonql.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import io
from pathlib import Path
from typing import Sequence
import numpy as np
import pytest
from cc_net import jsonql
def bar(small_... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/tests/test_normalizer.py | code/data_collection/cc/cc_net/tests/test_normalizer.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import cc_net.text_normalizer as txt
def test_unicode_punct():
weird = ",。、„”“«»1」「《》´∶:?!();–—.~’…━〈〉【】%"
replaced = ',.,""""""""... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/tests/test_regroup.py | code/data_collection/cc/cc_net/tests/test_regroup.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import time
from cc_net import jsonql, regroup
def check_regroup(tmp_path, regroup_fn, check_blocks_boundaries=False):
n_shards = 4
... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/tests/conftest.py | code/data_collection/cc/cc_net/tests/conftest.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import pytest
def _request_is_disabled(self, *args, **kwargs):
raise Exception(
f"Your code tried to call 'request' with: {arg... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/tests/test_parse_wet_file.py | code/data_collection/cc/cc_net/tests/test_parse_wet_file.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
from pathlib import Path
from cc_net import process_wet_file
def test_parsing():
sample = Path(__file__).parent / "data" / "sample.wa... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/tests/test_minify.py | code/data_collection/cc/cc_net/tests/test_minify.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import json
from pathlib import Path
import pytest
import cc_net
import cc_net.minify as minify
from cc_net import jsonql, process_wet_fil... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/tests/__init__.py | code/data_collection/cc/cc_net/tests/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
#
| python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/tests/test_flat_hash_set.py | code/data_collection/cc/cc_net/tests/test_flat_hash_set.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import numpy as np
import pytest
from cc_net.flat_hash_set import HASH_TYPE, FlatHashSet, NaiveHashSet
def as_dict(flat_hash_set) -> dict... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/tests/test_dedup.py | code/data_collection/cc/cc_net/tests/test_dedup.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import json
from pathlib import Path
from typing import Iterable, Sequence
from cc_net import dedup, jsonql
from cc_net.dedup import str_ha... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/split_by_lang.py | code/data_collection/cc/cc_net/cc_net/split_by_lang.py | # Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import collections
from pathlib import Path
from typing import Dict, Optional
import fasttext # type: igno... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/jsonql.py | code/data_collection/cc/cc_net/cc_net/jsonql.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
"""
Manipulate files containing one json per line.
"""
import argparse
import collections
import contextlib
import functools
import glob
imp... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | true |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/dedup.py | code/data_collection/cc/cc_net/cc_net/dedup.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
"""
Tools to remove duplicate paragraphs across one or several shards.
"""
import argparse
import gc
import hashlib
import logging
import m... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/regroup.py | code/data_collection/cc/cc_net/cc_net/regroup.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import logging
import subprocess
from pathlib import Path
from typing import List
import func_argparse
import numpy as np
from cc_net impo... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/get_wiki_cirrus.py | code/data_collection/cc/cc_net/cc_net/get_wiki_cirrus.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
"""
Creates mono-lingual corpus from Wikipedia.
"""
import functools
import re
import subprocess
import urllib.request
from pathlib import ... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/minify.py | code/data_collection/cc/cc_net/cc_net/minify.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import base64
import hashlib
import itertools
import urllib.parse
from pathlib import Path
from typing import Dict, Iterable, List, Optional... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/process_wet_file.py | code/data_collection/cc/cc_net/cc_net/process_wet_file.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import contextlib
import functools
import logging
import re
import tempfile
import time
import urllib.request
from pathlib import Path
from ... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/__main__.py | code/data_collection/cc/cc_net/cc_net/__main__.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import func_argparse
import cc_net.mine
def main():
func_argparse.parse_and_call(cc_net.mine.get_main_parser())
if __name__ == "__... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/mine.py | code/data_collection/cc/cc_net/cc_net/mine.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
"""
Main script to download a CC dump, remove duplicates, split by language and
filter the documents.
The pipeline parameters are described... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/__init__.py | code/data_collection/cc/cc_net/cc_net/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
| python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/text_normalizer.py | code/data_collection/cc/cc_net/cc_net/text_normalizer.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import re
import unicodedata
UNICODE_PUNCT = {
",": ",",
"。": ".",
"、": ",",
"„": '"',
"”": '"',
"“": '"',
"«":... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/execution.py | code/data_collection/cc/cc_net/cc_net/execution.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import functools
import itertools
import logging
import os
import sys
import time
import warnings
from pathlib import Path
from typing impor... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/tokenizer.py | code/data_collection/cc/cc_net/cc_net/tokenizer.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import time
from typing import Dict, Optional
import sacremoses # type: ignore
from cc_net import jsonql, text_normalizer
class RobustT... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/perplexity.py | code/data_collection/cc/cc_net/cc_net/perplexity.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import argparse
import time
from pathlib import Path
from typing import Dict, List, Optional, Sequence, Tuple, Union
import kenlm # type: ... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/flat_hash_set.py | code/data_collection/cc/cc_net/cc_net/flat_hash_set.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import sys
import time
import warnings
from typing import Iterable, Iterator, Sequence, Sized, Tuple, Type
import numpy as np
HASH_TYPE: T... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/tools/make_dmoz_corpus.py | code/data_collection/cc/cc_net/cc_net/tools/make_dmoz_corpus.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
"""
This code is used to train a fastText classifier to label document with DMOZ categories.
The data, distributed under the cc-by 3.0 lice... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/tools/expand_corpus.py | code/data_collection/cc/cc_net/cc_net/tools/expand_corpus.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
"""
Tools to search sentences in CC similar to sentences in another corpus.
"""
import functools
import logging
import math
import subproce... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/tools/dl_cc_100.py | code/data_collection/cc/cc_net/cc_net/tools/dl_cc_100.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
import contextlib
import functools
import gzip
import logging
import multiprocessing
from collections import defaultdict
from pathlib import... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/cc/cc_net/cc_net/tools/__init__.py | code/data_collection/cc/cc_net/cc_net/tools/__init__.py | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false | |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/github/language_mapping.py | code/data_collection/github/language_mapping.py | _LANG_TO_EXTENSION = {
"Assembly": ["asm"],
"Batchfile": ["bat", "cmd"],
"C": ["c", "h"],
"C#": ["cs"],
"C++": ["cpp", "hpp", "c++", "h++", "cc", "hh", "C", "H"],
"CMake": ["cmake"],
"CSS": ["css"],
"Dockerfile": ["dockerfile", "Dockerfile"],
"FORTRAN": ['f90', 'f', 'f03', 'f08', 'f7... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/github/deduplicate.py | code/data_collection/github/deduplicate.py | import hashlib
import os
ROOT = 'Code' # NOTE: hard-coded.
seen = set()
count = 0
dups = 0
print("Begin to deduplicate data")
for root_dir, _, files in os.walk(ROOT):
for file in files:
count += 1
file_path = os.path.join(root_dir, file)
# Hash the entire file's content.
with open(file_path, 'rb') as f:
... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/github/data_encapsulation.py | code/data_collection/github/data_encapsulation.py | import os
import json
import argparse
from language_mapping import _EXTENSION_TO_LANG,_LANG_TO_EXTENSION
ROOT="Code" # NOTE: hard-coded.
INFO="InfoLists"
OUTPUT_DIR=r"RawData"
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--language", type=str, help="Language to search fo... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/github/minhash_deduplication.py | code/data_collection/github/minhash_deduplication.py | import json
import multiprocessing as mp
from multiprocessing import freeze_support
import re
from collections import defaultdict
from functools import partial
from typing import Dict, List, Optional, Set, Tuple, Type
from datasets import Dataset
from datasketch import MinHash, MinHashLSH
from dpu_utils.utils.iterator... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/github/data_clean.py | code/data_collection/github/data_clean.py | import gzip
import hashlib
import json
import multiprocessing
import os
import re
import shutil
import time
from pathlib import Path
import numpy as np
from datasets import load_dataset,Features,Value
from minhash_deduplication import deduplicate_dataset
from dataclasses import dataclass, field
from typing import Opti... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/github/gh_crawler.py | code/data_collection/github/gh_crawler.py | import requests
import sys
import time
import json
import os
import argparse
# Insert GitHub API token here, in place of *TOKEN*.
headers = {"Authorization": "token *TOKEN*"}
def run_query(max_stars):
end_cursor = None
repositories = set()
info_list={}
while end_cursor != "":
query = f"""
{{
search(quer... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/github/extract_code.py | code/data_collection/github/extract_code.py | """Copies all files belonging to a given language to a new directory."""
import os
import sys
from shutil import copyfile
from language_mapping import _EXTENSION_TO_LANG,_LANG_TO_EXTENSION
MAX_FILE_SIZE = 1024 ** 2 # 1 MB
MIN_FILE_TOKENS = 100
def main():
if len(sys.argv) <= 3:
raise ValueError('Provide a languag... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/arxiv/arxiv_downloader.py | code/data_collection/arxiv/arxiv_downloader.py | import xml.etree.ElementTree as ET
from easydict import EasyDict
import argparse
import queue
import subprocess
import signal
import sys
import threading
import os
THREAD_NUM = 4
CMD_TEMPLATE = "s3cmd get --recursive --skip-existing --requester-pays -q s3://arxiv/{} {} "
OUTPUT_DIR ="ArxivSrc"
ERROR_LOG = "error.log"
... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/arxiv/data_encapsulation.py | code/data_collection/arxiv/data_encapsulation.py | import os
import json
from utils import *
print("Encapsulating data...")
OUTPUT_DIR='data'
sh('mkdir -p '+OUTPUT_DIR)
info_dict=jsonl2dict('arxiv-metadata-oai-snapshot.json',key='id')
files=ls('clean_out')
with open(os.path.join(OUTPUT_DIR,"data.jsonl"),'w',encoding='utf-8') as f:
for file in files:
fi... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/arxiv/data_clean.py | code/data_collection/arxiv/data_clean.py | from utils import *
import re
import multiprocessing as mp
def clean(file):
with open(file,'r',encoding='utf-8') as f:
content = f.readlines()
new_content = []
for l in content:
if not l.strip().startswith(":::"):
new_content.append(l)
file_name = file.split("/")[-1]
... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/arxiv/utils.py | code/data_collection/arxiv/utils.py | import os
from functools import reduce
import operator
# import mailparser
# import lm_dataformat as lmd
from tqdm import tqdm
import json
class ExitCodeError(Exception): pass
def sh(x):
if os.system(x): raise ExitCodeError()
def ls(x):
return [x + '/' + fn for fn in os.listdir(x)]
def lsr(x):
if os.p... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/arxiv/arxiv_extractor.py | code/data_collection/arxiv/arxiv_extractor.py | from utils import *
import magic
mime = magic.Magic(mime=True)
import multiprocessing as mp
import chardet
import time
import os
sh("mkdir -p tmp tmp2 out done fallback_needed errored")
def any_to_utf8(b):
try:
return b.decode('utf-8')
except UnicodeDecodeError:
guess = chardet.detect(b)['enc... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/data_collection/arxiv/data_tag_filter.py | code/data_collection/arxiv/data_tag_filter.py | import json
import os
INPUT= 'data/data.jsonl'
SAVE='math_data/data.jsonl'
KEY = 'catagories'
l=[]
with open(INPUT, 'r', encoding="utf-8") as f:
for line in f:
data = json.loads(line)
if data[KEY].split(" ")[0].split(".")[0]=="math":
l.append(data)
os.makedirs(os.path.dirname(SAVE), ... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/evaluation/main.py | code/evaluation/main.py | import torch
from torch.utils.data import DataLoader
import argparse
import torch
from transformers import (
AutoTokenizer,
AutoModelForCausalLM,
)
from packed_dataset import EvalDataset
import numpy as np
from tqdm import tqdm
def cross_entropy(
logits, targets, attention_mask: torch.Tensor = None
):
... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
hkust-nlp/llm-compression-intelligence | https://github.com/hkust-nlp/llm-compression-intelligence/blob/ff39c4161d4cd16c7603d85f436da123773448bb/code/evaluation/packed_dataset.py | code/evaluation/packed_dataset.py | import numpy as np
import torch
from torch.utils.data import Dataset
from datasets import load_dataset
import math
class EvalDataset(Dataset):
def __init__(self, args, task_name, block_size, stride, tokenizer, file_num=-1, dtype="auto", vocab_size=None):
self.args = args
self.task_name = task_name... | python | MIT | ff39c4161d4cd16c7603d85f436da123773448bb | 2026-01-05T07:14:42.211982Z | false |
henne49/dbus-opendtu | https://github.com/henne49/dbus-opendtu/blob/9266cc79e781ef8c8e75749922f8634ddd2b7989/constants.py | constants.py | '''Global constants'''
from helpers import _kwh, _a, _w, _v
DTUVARIANT_AHOY = "ahoy"
DTUVARIANT_OPENDTU = "opendtu"
DTUVARIANT_TEMPLATE = "template"
PRODUCTNAME = "henne49_dbus-opendtu"
CONNECTION = "TCP/IP (HTTP)"
MODE_TIMEOUT = "timeout"
MODE_RETRYCOUNT = "retrycount"
# Status codes for the DTU
STATUSCODE_STARTUP ... | python | MIT | 9266cc79e781ef8c8e75749922f8634ddd2b7989 | 2026-01-05T07:14:42.526396Z | false |
henne49/dbus-opendtu | https://github.com/henne49/dbus-opendtu/blob/9266cc79e781ef8c8e75749922f8634ddd2b7989/dbus_opendtu.py | dbus_opendtu.py | #!/usr/bin/env python
'''module to read data from dtu/template and show in VenusOS'''
from imports import *
def getConfig():
"""
Reads the configuration from a config.ini file and sets up logging.
The function reads the configuration file located in the same directory as the script.
It configures th... | python | MIT | 9266cc79e781ef8c8e75749922f8634ddd2b7989 | 2026-01-05T07:14:42.526396Z | false |
henne49/dbus-opendtu | https://github.com/henne49/dbus-opendtu/blob/9266cc79e781ef8c8e75749922f8634ddd2b7989/imports.py | imports.py | # imports.py
""" Imports for the project """
# pylint: disable=w0611
# system imports:
import logging
import logging.handlers
import os
import configparser
import sys
# our imports:
import constants
import tests
from helpers import *
# Victron imports:
from dbus_service import DbusService
if sys.version_info.major... | python | MIT | 9266cc79e781ef8c8e75749922f8634ddd2b7989 | 2026-01-05T07:14:42.526396Z | false |
henne49/dbus-opendtu | https://github.com/henne49/dbus-opendtu/blob/9266cc79e781ef8c8e75749922f8634ddd2b7989/helpers.py | helpers.py | '''Module containing various helper functions'''
# File specific rules
# pylint: disable=broad-except
# system imports
import functools
import time
import os
# our imports:
import logging
# region formatting helping functions (used in constant)
def _kwh(_p, value: float) -> str:
return f"{value:.2f}KWh"
def ... | python | MIT | 9266cc79e781ef8c8e75749922f8634ddd2b7989 | 2026-01-05T07:14:42.526396Z | false |
henne49/dbus-opendtu | https://github.com/henne49/dbus-opendtu/blob/9266cc79e781ef8c8e75749922f8634ddd2b7989/tests.py | tests.py | '''(Unit) tests'''
# system imports:
import json
import logging
import os
import time
# our imports:
import constants
# Victron imports:
from dbus_service import DbusService
from helpers import get_value_by_path
OPENDTU_TEST_DATA_FILE = "docs/opendtu_status.json"
AHOY_TEST_DATA_FILE_LIVE = "docs/ahoy_0.5.93_live.j... | python | MIT | 9266cc79e781ef8c8e75749922f8634ddd2b7989 | 2026-01-05T07:14:42.526396Z | false |
henne49/dbus-opendtu | https://github.com/henne49/dbus-opendtu/blob/9266cc79e781ef8c8e75749922f8634ddd2b7989/dbus_service.py | dbus_service.py | '''DbusService and PvInverterRegistry'''
# File specific rules
# pylint: disable=broad-except, import-error, wrong-import-order, wrong-import-position
# region [Imports]
# system imports:
import configparser
import os
import platform
import sys
import logging
import time
import requests # for http GET
from requests... | python | MIT | 9266cc79e781ef8c8e75749922f8634ddd2b7989 | 2026-01-05T07:14:42.526396Z | true |
henne49/dbus-opendtu | https://github.com/henne49/dbus-opendtu/blob/9266cc79e781ef8c8e75749922f8634ddd2b7989/tests/test_dbus_service.py | tests/test_dbus_service.py | ''' This file contains the unit tests for the DbusService class. '''
import time
import unittest
from unittest.mock import MagicMock, patch
import os
import json
import requests
from constants import MODE_TIMEOUT
from dbus_service import DbusService
def mocked_requests_get(url, params=None, **kwargs): # pylint: dis... | python | MIT | 9266cc79e781ef8c8e75749922f8634ddd2b7989 | 2026-01-05T07:14:42.526396Z | false |
henne49/dbus-opendtu | https://github.com/henne49/dbus-opendtu/blob/9266cc79e781ef8c8e75749922f8634ddd2b7989/tests/__init__.py | tests/__init__.py | python | MIT | 9266cc79e781ef8c8e75749922f8634ddd2b7989 | 2026-01-05T07:14:42.526396Z | false | |
henne49/dbus-opendtu | https://github.com/henne49/dbus-opendtu/blob/9266cc79e781ef8c8e75749922f8634ddd2b7989/tests/test_dbus_opendtu.py | tests/test_dbus_opendtu.py | """ Unit tests for the dbus_opendtu.py module """
import unittest
from unittest.mock import patch, MagicMock, mock_open, ANY
import sys
import os
import configparser
# Add the parent directory of dbus_opendtu to the system path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
# Mock... | python | MIT | 9266cc79e781ef8c8e75749922f8634ddd2b7989 | 2026-01-05T07:14:42.526396Z | false |
henne49/dbus-opendtu | https://github.com/henne49/dbus-opendtu/blob/9266cc79e781ef8c8e75749922f8634ddd2b7989/tests/test_helpers.py | tests/test_helpers.py | ''' This file contains the unit tests for the helper functions in the helpers.py file. '''
# file ignores
# pylint: disable=too-many-instance-attributes
import sys
import os
import unittest
from unittest.mock import MagicMock
import json
# Add the parent directory of dbus_opendtu to the system path
sys.path.insert(0... | python | MIT | 9266cc79e781ef8c8e75749922f8634ddd2b7989 | 2026-01-05T07:14:42.526396Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/main.py | main.py | # python 3
# -*- coding:utf-8 -*-
"""
Created on 2023/11/23
@author: Chen Qian
@e-mail: chenqian2020@sjtu.edu.cn
"""
"""
Set <--data_dir> to the directory of the CWRU dataset firstly! (for example: './Datasets_dir/CWRU')
"""
import argparse
import os
from datetime import datetime
from utils.logger import setlogger
imp... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/PostProcess/Acc_statistic.py | PostProcess/Acc_statistic.py | """
Created on 2023/11/23
@author: Chen Qian
@e-mail: chenqian2020@sjtu.edu.cn
"""
"""
This script is used to extract the training info from the log files and save to excel, and plot the accuracy figure.
"""
import os
from process_utils.processlib import ExtractInfo
from process_utils.processlib import acc2csv
from pr... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/PostProcess/TrainSequentially.py | PostProcess/TrainSequentially.py | """
Created on 2023/11/23
@author: Chen Qian
@e-mail: chenqian2020@sjtu.edu.cn
"""
"""
This script is used to train the models sequentially.
Before run this, please set <--data_dir> to the directory of the CWRU dataset in <main.py> first.
"""
import os, sys
if __name__ == '__main__':
# set the current directory
... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/PostProcess/process_utils/PlotAccuracy.py | PostProcess/process_utils/PlotAccuracy.py | """
Created on 2023/11/23
@author: Chen Qian
@e-mail: chenqian2020@sjtu.edu.cn
"""
import pandas as pd
import os
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib as mpl
def setseaborn():
# set color
current_cmap = sns.color_palette("deep")
sns.set(style="whitegri... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/PostProcess/process_utils/processlib.py | PostProcess/process_utils/processlib.py | """
Created on 2023/11/23
@author: Chen Qian
@e-mail: chenqian2020@sjtu.edu.cn
"""
import os
import numpy as np
from datetime import datetime
import pandas as pd
def ExtractInfo(filepath,append_acc = True):
"""
extract the training info from the log file
"""
start_time, record_time = None, None
pr... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/Datasets/CWRU.py | Datasets/CWRU.py | """
Created on 2023/11/23
@author: Chen Qian
@e-mail: chenqian2020@sjtu.edu.cn
"""
import pandas as pd
from Datasets.Dataset_utils.DatasetsBase import dataset
import Datasets.Dataset_utils.sequence_aug as aug1d
from Datasets.get_files.CWRU_get_files import get_files
from Datasets.get_files.generalfunciton import data_... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/Datasets/__init__.py | Datasets/__init__.py | from Datasets.CWRU import CWRU | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/Datasets/Dataset_utils/DatasetsBase.py | Datasets/Dataset_utils/DatasetsBase.py | #!/usr/bin/python
# -*- coding:utf-8 -*-
from torch.utils.data import Dataset
class dataset(Dataset):
def __init__(self, list_data, transform=None):
self.seq_data = list_data['data'].tolist()
self.labels = list_data['label'].tolist()
self.transforms = transform
def __len__(self):
... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/Datasets/Dataset_utils/sequence_aug.py | Datasets/Dataset_utils/sequence_aug.py |
import numpy as np
import random
from scipy.signal import resample
class Compose(object):
def __init__(self, transforms):
self.transforms = transforms
def __call__(self, seq):
for t in self.transforms:
seq = t(seq)
return seq
class Reshape(object):
def __call__(self... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/Datasets/get_files/CWRU_get_files.py | Datasets/get_files/CWRU_get_files.py | import os
from scipy.io import loadmat
from Datasets.get_files.generalfunciton import sig_process
from Datasets.get_files.generalfunciton import add_noise
import numpy as np
import random
# set random seed
seed = 999
np.random.seed(seed)
random.seed(seed)
datasetname = ["12k Drive End Bearing Fault Data", "12k Fan En... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/Datasets/get_files/generalfunciton.py | Datasets/get_files/generalfunciton.py | import numpy as np
# import pywt
from scipy import signal
import pandas as pd
from torch.utils.data import Dataset
import random
# random.seed(999)
seed = 999
np.random.seed(seed)
random.seed(seed)
def add_noise(sig,SNR): # add noise to sig
noise = np.random.randn(*sig.shape)
noise_var = sig.var() / np.power(... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/utils/train_utils.py | utils/train_utils.py | #!/usr/bin/python
# -*- coding:utf-8 -*-
"""
Created on 2023/11/23
@author: Chen Qian
@e-mail: chenqian2020@sjtu.edu.cn
"""
import logging
import os
import time
import warnings
import torch
from torch import nn
from torch import optim
import Models
import Datasets
import matplotlib.pyplot as plt
from utils.mysummary i... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/utils/logger.py | utils/logger.py | #!/usr/bin/python
# -*- coding:utf-8 -*-
import logging
def setlogger(path):
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logFormatter = logging.Formatter("%(asctime)s %(message)s", "%m-%d %H:%M:%S")
fileHandler = logging.FileHandler(path)
fileHandler.setFormatter(logFormatter)
... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/utils/mysummary.py | utils/mysummary.py | """
Based on torchsummary.summary
"""
import torch
import torch.nn as nn
from collections import OrderedDict
import numpy as np
def summary(model, input_size, batch_size=-1, device="cuda"):
return_info = ""
def register_hook(module):
def hook(module, input, output):
class_name = str(modu... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/Models/TFN.py | Models/TFN.py | """
Created on 2023/11/23
@author: Chen Qian
@e-mail: chenqian2020@sjtu.edu.cn
"""
from Models.TFconvlayer import *
from Models.BackboneCNN import CNN
from torch.nn import Conv1d
from utils.mysummary import summary
class Base_FUNC_CNN(CNN):
"""
the base class of TFN
"""
FuncConv1d = BaseFuncConv1d
... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/Models/TFconvlayer.py | Models/TFconvlayer.py | """
Created on 2023/11/23
@author: Chen Qian
@e-mail: chenqian2020@sjtu.edu.cn
"""
from torch import nn
import torch
import numpy as np
import random
import os
import torch.nn.init as init
import math
import torch.nn.functional as F
# random seed
seed = 999
np.random.seed(seed)
random.seed(seed)
os.environ['PYTHONHAS... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
ChenQian0618/TFN | https://github.com/ChenQian0618/TFN/blob/bb8af32c380fa047631b960e6a08ed0b261f1874/Models/BackboneCNN.py | Models/BackboneCNN.py | #!/usr/bin/python
# -*- coding:utf-8 -*-
from torch import nn
import torch
from utils.mysummary import summary
# ----------------------------inputsize = 1024-------------------------------------------------------------------------
class CNN(nn.Module):
def __init__(self, in_channels=1, out_channels=10,kernel_size=... | python | MIT | bb8af32c380fa047631b960e6a08ed0b261f1874 | 2026-01-05T07:14:43.861108Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.