repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/disco_project/guided_diffusion/guided_diffusion/losses.py | """
Helpers for various likelihood-based losses. These are ported from the original
Ho et al. diffusion models codebase:
https://github.com/hojonathanho/diffusion/blob/1e0dceb3b3495bbe19116a5e1b3596cd0706c543/diffusion_tf/utils.py
"""
import numpy as np
import torch as th
def normal_kl(mean1, logvar1, mean2, logvar... | 2,502 | 32.824324 | 109 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/disco_project/guided_diffusion/guided_diffusion/logger.py | """
Logger copied from OpenAI baselines to avoid extra RL-based dependencies:
https://github.com/openai/baselines/blob/ea25b9e8b234e6ee1bca43083f8f3cf974143998/baselines/logger.py
"""
import os
import sys
import os.path as osp
import json
import time
import datetime
import tempfile
import warnings
from collections imp... | 13,964 | 27.269231 | 132 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/disco_project/guided_diffusion/guided_diffusion/nn.py | """
Various utilities for neural networks.
"""
import math
import torch as th
import torch.nn as nn
# PyTorch 1.7 has SiLU, but we support PyTorch 1.5.
class SiLU(nn.Module):
def forward(self, x):
return x * th.sigmoid(x)
class GroupNorm32(nn.GroupNorm):
def forward(self, x):
return super(... | 5,835 | 29.554974 | 99 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/disco_project/guided_diffusion/guided_diffusion/fp16_util.py | """
Helpers to train with 16-bit precision.
"""
import numpy as np
import torch as th
import torch.nn as nn
from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors
from . import logger
INITIAL_LOG_LOSS_SCALE = 20.0
def convert_module_to_f16(ll):
"""
Convert primitive modules to float16.
... | 7,955 | 32.56962 | 114 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/disco_project/guided_diffusion/guided_diffusion/unet.py | from abc import abstractmethod
import math
import numpy as np
import torch as th
import torch.nn as nn
import torch.nn.functional as F
from .fp16_util import convert_module_to_f16, convert_module_to_f32
from .nn import (
checkpoint,
conv_nd,
linear,
avg_pool_nd,
zero_module,
normalization,
... | 34,109 | 33.94877 | 124 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/disco_project/guided_diffusion/guided_diffusion/script_util.py | import argparse
import inspect
from . import gaussian_diffusion as gd
from .respace import SpacedDiffusion, space_timesteps
from .unet import SuperResModel, EncoderUNetModel
NUM_CLASSES = 1000
def diffusion_defaults():
"""
Defaults for image and classifier training.
"""
return dict(
learn_si... | 12,461 | 26.269147 | 88 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/disco_project/guided_diffusion/guided_diffusion/gaussian_diffusion.py | """
This code started out as a PyTorch port of Ho et al's diffusion models:
https://github.com/hojonathanho/diffusion/blob/1e0dceb3b3495bbe19116a5e1b3596cd0706c543/diffusion_tf/diffusion_utils_2.py
Docstrings have been added, as well as DDIM sampling and a new collection of beta schedules.
"""
import enum
import math... | 50,680 | 37.482156 | 185 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/disco_project/guided_diffusion/guided_diffusion/__init__.py | """
Codebase for "Improved Denoising Diffusion Probabilistic Models".
"""
| 74 | 17.75 | 65 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/disco_project/guided_diffusion/guided_diffusion/respace.py | import numpy as np
import torch as th
from .gaussian_diffusion import GaussianDiffusion
def space_timesteps(num_timesteps, section_counts):
"""
Create a list of timesteps to use from an original diffusion process,
given the number of timesteps we want to take from equally-sized portions
of the origin... | 5,192 | 39.255814 | 85 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pretrain_erlangshen_deberta_v2/pretrain_deberta.py | from dataclasses import dataclass
from transformers import (
DebertaV2Config,
DebertaV2ForMaskedLM,
AutoTokenizer,
)
from pytorch_lightning import (
LightningModule,
Trainer,
)
from pytorch_lightning.callbacks import (
LearningRateMonitor,
)
import argparse
import torch
import os
import numpy as... | 8,886 | 37.97807 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/tcbert/example.py | import argparse
from fengshen.pipelines.tcbert import TCBertPipelines
from pytorch_lightning import seed_everything
def main():
seed_everything(123)
total_parser = argparse.ArgumentParser("Topic Classification")
total_parser = TCBertPipelines.piplines_args(total_parser)
args = total_parser.parse_args()... | 3,693 | 41.45977 | 94 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/tcbert/__init__.py | 0 | 0 | 0 | py | |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/ziya_inference/llama_cpp_quantizatin_inference.py | """
dependencies
llama.cpp (https://github.com/ggerganov/llama.cpp)
llama-cpp-python (https://github.com/abetlen/llama-cpp-python)
llama.cpp
1. 通过llama.cpp将模型转换为ggml格式
2. 参考llama.cpp对转换后的模型量化到 (q4_0, q4_1, q5_0, q5_1, q8_0)
- 在转换过程中会遇到tokenizer对不齐的问题,自行在词表中添加相应个数token即可
... | 1,505 | 31.73913 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/ziya_inference/hf_quantizatin_inference.py | """
这是基于hugging face社区开源的框架accelerate制定的基础量化推理方案
该框架主要实现了int8、int4量化,以及cpu或者disk offload
实现了用低存储,小设备运行大模型
具体可以见wiki:http://wiki.team.idea.edu.cn/pages/viewpage.action?pageId=31464125
"""
import time
from transformers import AutoModelForCausalLM, AutoTokenizer
import bitsandbytes as bnb
from bitsandbytes.nn import Linea... | 2,638 | 35.652778 | 114 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/qa_t5/finetune_t5_cmrc.py | # -*- encoding: utf-8 -*-
'''
Copyright 2022 The International Digital Economy Academy (IDEA). CCNL team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.o... | 17,183 | 37.101996 | 100 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/qa_t5/qa_dataset.py | # -*- encoding: utf-8 -*-
'''
Copyright 2022 The International Digital Economy Academy (IDEA). CCNL team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.o... | 6,086 | 31.37766 | 96 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/hubert/pretrain_hubert.py | import fengshen.data.hubert.hubert_dataset as datasets
from fengshen.data.universal_datamodule import UniversalDataModule
from transformers import HubertConfig, HubertModel
# from transformers.models.hubert.modeling_hubert import _compute_mask_indices
import argparse
from fairseq.data import Dictionary
from pytorch_lig... | 11,643 | 39.430556 | 109 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pretrain_erlangshen_bert/pretrain_erlangshen.py | from dataclasses import dataclass
from transformers import (
MegatronBertConfig,
MegatronBertForPreTraining,
AutoTokenizer,
)
from pytorch_lightning import (
LightningModule,
Trainer,
)
from pytorch_lightning.callbacks import (
LearningRateMonitor,
)
import argparse
import torch
import os
import... | 9,575 | 39.235294 | 120 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/wenzhong_qa/finetune_medicalQA.py | from transformers import GPT2LMHeadModel
from data.task_dataloader.medicalQADataset import GPT2QADataModel
from transformers.optimization import get_linear_schedule_with_warmup
from pytorch_lightning import Trainer, loggers
from pytorch_lightning.callbacks import ModelCheckpoint
import pytorch_lightning as pl
import ar... | 7,423 | 40.943503 | 110 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/wenzhong_qa/finetune_wenzhong.py | # sys.path.append('./')
import os
import torch
import argparse
import pytorch_lightning as pl
from pytorch_lightning.callbacks import ModelCheckpoint
from pytorch_lightning import Trainer, loggers
from transformers.optimization import get_linear_schedule_with_warmup
from transformers import GPT2LMHeadModel
from fengshe... | 6,611 | 41.935065 | 114 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/finetune_bart_qg/utils.py | # -*- encoding: utf-8 -*-
'''
Copyright 2022 The International Digital Economy Academy (IDEA). CCNL team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.o... | 2,208 | 30.112676 | 96 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/finetune_bart_qg/finetune_bart.py | # -*- encoding: utf-8 -*-
'''
Copyright 2022 The International Digital Economy Academy (IDEA). CCNL team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.o... | 17,301 | 39.237209 | 141 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/zen1_finetune/fengshen_token_level_ft_task.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by a... | 26,317 | 39.614198 | 163 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/zen1_finetune/fengshen_sequence_level_ft_task.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by a... | 24,857 | 39.684124 | 130 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pretrain_taiyi_clip/pretrain.py | from pytorch_lightning import (
LightningModule,
Trainer,
)
from pytorch_lightning.callbacks import (
LearningRateMonitor,
)
from fengshen.models.clip import (
TaiyiCLIPModel,
TaiyiCLIPProcessor,
)
from fengshen.models.model_utils import (
add_module_args,
configure_optimizers,
get_total... | 12,711 | 40.139159 | 113 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pretrain_taiyi_clip/test.py | from pytorch_lightning import (
Trainer,
)
from fengshen.models.model_utils import (
add_module_args,
)
import argparse
from fengshen.data.universal_datamodule import UniversalDataModule
from fengshen.utils.universal_checkpoint import UniversalCheckpoint
from fengshen.examples.pretrain_taiyi_clip.pretrain impor... | 1,404 | 36.972973 | 97 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pretrain_taiyi_clip/flickr_datasets.py | # 这里这个dataset只是临时测试用的,所以暂时用最简陋的方式放在这里,后续会优化
from torch.utils.data import Dataset
from PIL import Image
class flickr30k_CNA(Dataset):
def __init__(self, img_root_path=None,
text_annot_path=None,
data_process_fn=None):
self.images = []
self.captions = []
sel... | 1,241 | 33.5 | 68 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/summary/seq2seq_summary.py |
import torch
import os
import argparse
import json
import pytorch_lightning as pl
from fengshen.models.model_utils import add_module_args
from fengshen.data.task_dataloader.task_datasets import AbstractCollator
from fengshen.data.universal_datamodule import UniversalDataModule
from fengshen.utils.universal_checkpoint ... | 9,184 | 45.388889 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/mt5_summary/mt5_summary.py | from fengshen.data.task_dataloader.task_datasets import LCSTSDataModel
from transformers import T5Tokenizer, MT5ForConditionalGeneration
from transformers.optimization import get_linear_schedule_with_warmup
from pytorch_lightning import Trainer, loggers
from pytorch_lightning.callbacks import ModelCheckpoint
from trans... | 9,924 | 41.41453 | 112 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/mt5_summary/fastapi_mt5_summary.py | import os
import sys
import uvicorn
import torch
from fastapi import Body, FastAPI
from transformers import T5Tokenizer, MT5ForConditionalGeneration
import pytorch_lightning as pl
sys.path.append(os.path.abspath(os.path.join(
os.path.dirname(__file__), os.path.pardir)))
os.environ["CUDA_VISIBLE_DEVICES"] = '5'
os.e... | 3,393 | 35.106383 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/finetune_taiyi_stable_diffusion/finetune.py | import os
import torch
import argparse
from pytorch_lightning import (
LightningModule,
Trainer,
)
from pytorch_lightning.callbacks import (
LearningRateMonitor,
)
from fengshen.data.universal_datamodule import UniversalDataModule
from fengshen.models.model_utils import (
add_module_args,
configure_... | 7,853 | 39.484536 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/finetune_taiyi_stable_diffusion/evaluate_model.py | import pytorch_lightning as pl
import torch.nn as nn
import torch.nn.functional as F
import torch
import timm
from torchvision import transforms as T
import open_clip
import sys
import torch
import json
from transformers import BertModel, BertTokenizer
from PIL import Image
from diffusers import StableDiffusionPipeline... | 11,944 | 39.491525 | 187 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pegasus/pretrain_pegasus.py | # -*- coding: utf-8 -*-
from fengshen.models.model_utils import add_module_args
from transformers import PegasusForConditionalGeneration, PegasusConfig
from pytorch_lightning import Trainer, loggers, LightningModule
from pytorch_lightning.callbacks import LearningRateMonitor
from tokenizers_pegasus import PegasusToke... | 7,247 | 38.824176 | 92 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pegasus/data_utils.py | # -*- coding: utf-8 -*-
import re
import six
import unicodedata
import torch
import rouge
import numpy as np
import random
# from fengshen.examples.pegasus.pegasus_utils import text_segmentate
import sys
sys.path.append('../../../')
rouge = rouge.Rouge()
is_py2 = six.PY2
if not is_py2:
basestring = str
def ... | 9,799 | 29.625 | 80 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pegasus/tokenizers_pegasus.py | from fengshen.examples.pegasus.data_utils import (
_is_control,
_is_punctuation,
_is_whitespace,
_is_chinese_char)
from transformers import PreTrainedTokenizer
from transformers import logging
from typing import List, Optional, Tuple, Union
import collections
import os
import unicodedata
import re
impor... | 25,507 | 41.513333 | 120 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clip_finetune/clip_finetune_flickr.py | import sys
sys.path.append('../../')
from data.clip_dataloader.flickr import FlickrDataModule
import pytorch_lightning as pl
import numpy as np
import torch
from torch.optim.lr_scheduler import CosineAnnealingWarmRestarts
import torch.nn.functional as F
import math
import copy
import argparse
from transformers import C... | 11,460 | 43.080769 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/ziya_llama/llama_generate.py |
import torch
from transformers import LlamaForCausalLM, AutoTokenizer
from typing import List
import torch.nn.functional as F
def zero_pad_sequences(sequences: List[torch.Tensor], side: str = 'left', padding_value: int = 0) -> torch.Tensor:
assert side in ('left', 'right')
max_len = max(seq.size(0) for seq in... | 2,398 | 35.348485 | 118 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/ziya_llama/finetune_ziya_llama.py | from asyncio.log import logger
from cgitb import lookup
from dataclasses import dataclass
import os
import deepspeed
import torch
import pytorch_lightning as pl
from pytorch_lightning.callbacks import LearningRateMonitor
from pytorch_lightning.loggers import WandbLogger
import argparse
from fengshen.models.model_utils ... | 9,179 | 38.74026 | 135 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/ziya_llama/sample_test.py | from transformers import LlamaTokenizer
import torch
def pad(ids, pad_id, max_length):
if len(ids) > max_length:
return ids[:max_length]
return ids + [pad_id] * (max_length - len(ids))
prompt_without_output = "<human>:{prompt}\n<bot>:"
def generate_samples(s, tokenizer, max_seq_length):
max_leng... | 2,660 | 39.938462 | 117 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/predict2submit/wsc_submit.py | import json
from tqdm import tqdm
import argparse
def save_data(data,file_path):
with open(file_path, 'w', encoding='utf8') as f:
for line in data:
json_data=json.dumps(line,ensure_ascii=False)
f.write(json_data+'\n')
def submit(file_path):
with open(file_path, 'r', encoding='... | 1,174 | 27.658537 | 70 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/predict2submit/ocnli_submit.py | import json
from tqdm import tqdm
import argparse
def save_data(data,file_path):
with open(file_path, 'w', encoding='utf8') as f:
for line in data:
json_data=json.dumps(line,ensure_ascii=False)
f.write(json_data+'\n')
def submit(file_path):
id2label={0:'contradiction',1:'neutr... | 911 | 27.5 | 76 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/predict2submit/c3_submit.py | import json
from tqdm import tqdm
import argparse
def save_data(data,file_path):
with open(file_path, 'w', encoding='utf8') as f:
for line in data:
json_data=json.dumps(line,ensure_ascii=False)
f.write(json_data+'\n')
def submit(file_path):
with open(file_path, 'r', encoding=... | 842 | 25.34375 | 66 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/predict2submit/cmrc2018_submit.py | import json
from tqdm import tqdm
import argparse
def save_data(data,file_path):
with open(file_path, 'w', encoding='utf8') as f:
json_data=json.dumps(data,ensure_ascii=False)
f.write(json_data+'\n')
def submit(file_path):
id2score={}
with open(file_path, 'r', encoding='utf8') as f:
... | 1,152 | 27.121951 | 90 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/predict2submit/tnews_submit.py | import json
from tqdm import tqdm
import argparse
def save_data(data,file_path):
with open(file_path, 'w', encoding='utf8') as f:
for line in data:
json_data=json.dumps(line,ensure_ascii=False)
f.write(json_data+'\n')
def submit(file_path):
id2label={"故事": "100",
"... | 1,255 | 25.723404 | 92 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/predict2submit/iflytek_submit.py | import json
from tqdm import tqdm
import argparse
def save_data(data,file_path):
with open(file_path, 'w', encoding='utf8') as f:
for line in data:
json_data=json.dumps(line,ensure_ascii=False)
f.write(json_data+'\n')
label2id={"打车": "0", "地图导航": "1", "免费W... | 5,047 | 30.55 | 1,563 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/predict2submit/csl_submit.py | import json
from tqdm import tqdm
import argparse
import numpy as np
def save_data(data,file_path):
with open(file_path, 'w', encoding='utf8') as f:
for line in data:
json_data=json.dumps(line,ensure_ascii=False)
f.write(json_data+'\n')
def load_data(file_path,is_training=False):
... | 2,349 | 27.313253 | 144 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/predict2submit/afqmc_submit.py | import json
from tqdm import tqdm
import argparse
def save_data(data,file_path):
with open(file_path, 'w', encoding='utf8') as f:
for line in data:
json_data=json.dumps(line,ensure_ascii=False)
f.write(json_data+'\n')
def submit(file_path):
id2label={0:'0',1:'1'}
with ope... | 879 | 25.666667 | 76 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/predict2submit/chid_submit.py | import json
from tqdm import tqdm
import argparse
import numpy as np
def save_data(data,file_path):
with open(file_path, 'w', encoding='utf8') as f:
json_data=json.dumps(data,ensure_ascii=False)
f.write(json_data+'\n')
def load_data(file_path,is_training=False):
with open(file_path, 'r', enco... | 1,869 | 24.972222 | 133 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/solution/clue_ubert.py | import argparse
from fengshen import UbertPipelines
import os
import json
from tqdm import tqdm
def load_data(data_path):
with open(data_path, 'r', encoding='utf8') as f:
lines = f.readlines()
samples = [json.loads(line) for line in tqdm(lines)]
return samples
def main():
total_parser = a... | 1,506 | 31.06383 | 81 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/solution/clue_unimc.py | import argparse
from fengshen.pipelines.multiplechoice import UniMCPipelines
import os
import json
import copy
from tqdm import tqdm
def load_data(data_path):
with open(data_path, 'r', encoding='utf8') as f:
lines = f.readlines()
samples = [json.loads(line) for line in tqdm(lines)]
return sampl... | 1,989 | 30.09375 | 77 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/data_preprocessing/c3_preprocessing.py | import json
from tqdm import tqdm
import os
import argparse
def load_data(file_path,is_training=False):
with open(file_path, 'r', encoding='utf8') as f:
lines = json.loads(''.join(f.readlines()))
result=[]
for line in tqdm(lines):
data = line
texta = '\n'.join(data... | 2,355 | 31.722222 | 84 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/data_preprocessing/ocnli_preprocessing.py | import json
from tqdm import tqdm
import os
import argparse
label2desc={'contradiction':'矛盾','neutral':'自然','entailment':'蕴含'}
def load_data(file_path,is_training=False):
with open(file_path, 'r', encoding='utf8') as f:
lines = f.readlines()
result=[]
for line in tqdm(lines):
... | 1,986 | 31.57377 | 80 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/data_preprocessing/cmrc2018_preprocessing.py | import json
from tqdm import tqdm
import os
from sklearn.utils import shuffle
import re
import argparse
def cut_sent(para):
para = re.sub('([。,,!?\?])([^”’])', r"\1\n\2", para) # 单字符断句符
para = re.sub('(\.{6})([^”’])', r"\1\n\2", para) # 英文省略号
para = re.sub('(\…{2})([^”’])', r"\1\n\2", para) # 中文省略号
... | 4,370 | 33.690476 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/data_preprocessing/iflytek_preprocessing.py | import json
from tqdm import tqdm
import os
import argparse
label2desc={
'银行': '银行',
'社区服务': '社区',
'电商': '电商',
'支付': '支付',
'经营养成': '养成',
'卡牌': '卡牌',
'借贷': '借贷',
'驾校': '驾校',
'理财': '理财',
'职考': '职考',
'新闻': '新闻',
'旅游资讯': '旅游',
... | 4,638 | 23.675532 | 88 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/data_preprocessing/chid_preprocessing.py | import json
from tqdm import tqdm
import os
import re
import argparse
mask_token='[MASK]'
label_mask='__'
def load_schema(train_answer,dev_answer):
with open(train_answer,'r',encoding='utf-8') as f:
train2id = json.loads(''.join(f.readlines()))
with open(dev_answer,'r',encoding='utf-8') as f:
... | 5,303 | 32.358491 | 113 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/data_preprocessing/afqmc_preprocessing.py | import json
from tqdm import tqdm
import os
import argparse
label2desc={"0": "不相似", "1": "相似"}
def load_data(file_path,is_training=False):
with open(file_path, 'r', encoding='utf8') as f:
lines = f.readlines()
result=[]
for line in tqdm(lines):
data = json.loads(line)
... | 1,930 | 31.183333 | 80 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/data_preprocessing/wsc_preprocessing.py | import json
from tqdm import tqdm
import os
import argparse
label2desc={'true':'是','false':'不是'}
def load_data(file_path,is_training=False):
with open(file_path, 'r', encoding='utf8') as f:
lines = f.readlines()
result=[]
for line in tqdm(lines):
data = json.loads(line)
... | 2,862 | 34.345679 | 84 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/data_preprocessing/csl_preprocessing.py | import json
from tqdm import tqdm
import os
import jieba.analyse
import argparse
label2desc={'1':'可以','0':'不能'}
def load_data(file_path,is_training=False):
with open(file_path, 'r', encoding='utf8') as f:
lines = f.readlines()
result=[]
for line in tqdm(lines):
data = json.lo... | 2,677 | 29.089888 | 80 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue1.1/data_preprocessing/tnews_preprocessing.py | import json
from tqdm import tqdm
import argparse
label2desc={"news_story": "故事",
"news_culture": "文化",
"news_entertainment": "娱乐",
"news_sports": "体育",
"news_finance": "财经",
"news_house": "房产",
"news_car": "汽车",
"news_ed... | 2,386 | 32.619718 | 90 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/sequence_tagging/finetune_sequence_tagging.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by a... | 12,218 | 37.545741 | 159 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/FastDemo/YuyuanQA.py | import requests
import langid
import streamlit as st
from translate import baiduTranslatorMedical
from translate import baiduTranslator
langid.set_languages(['en', 'zh'])
lang_dic = {'zh': 'en', 'en': 'zh'}
st.set_page_config(
page_title="余元医疗问答",
page_icon=":shark:",
# layout="wide",
initial_sidebar... | 2,493 | 33.638889 | 102 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/ubert/example.py | import argparse
from fengshen import UbertPipelines
import os
os.environ["CUDA_VISIBLE_DEVICES"] = '6'
def main():
total_parser = argparse.ArgumentParser("TASK NAME")
total_parser = UbertPipelines.pipelines_args(total_parser)
args = total_parser.parse_args()
# 设置一些训练要使用到的参数
args.pretrained_model_... | 4,235 | 43.125 | 110 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/uniex/example.py | import argparse
from fengshen.pipelines.information_extruction import UniEXPipelines
import os
import json
from tqdm import tqdm
import copy
import time
def load_data(data_path):
with open(data_path, 'r', encoding='utf8') as f:
lines = f.readlines()
samples = [json.loads(line) for line in tqdm(lin... | 1,547 | 27.666667 | 77 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/translate/finetune_deltalm.py | # !/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
import json
import argparse
import torch
import os
import logging
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from pytorch_lightning.utilities import rank_zero_info
from sacrebleu.metrics import BLEU
from fengshen.utils.utils import ch... | 18,263 | 39.586667 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/translate/prepare_dataset.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import json
import os
def main(file_path, src_lang, tgt_lang):
file_list = ["train", "valid", "test"]
for filename in file_list:
sys.stderr.write("**** Start processing {} ... ****\n".format(filename))
src_full_path = os.path.join(file... | 1,278 | 32.657895 | 99 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pretrain_randeng_bart/pretrain_bart.py | from transformers import AutoTokenizer, BartForConditionalGeneration, BartConfig
from pytorch_lightning import (
LightningModule,
Trainer,
)
from pytorch_lightning.callbacks import LearningRateMonitor
from dataclasses import dataclass
import os
import argparse
import torch
import math
import time
from torch.uti... | 11,778 | 40.769504 | 107 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/GAVAE/generate.py | import torch
from transformers import BertTokenizer,T5Tokenizer
from fengshen.models.GAVAE.GAVAEModel import GAVAEModel
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
encoder_tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Randeng-GAVAE-1.2B-Augmentation-Chinese")
decoder_tokenizer = T5Toke... | 1,783 | 73.333333 | 188 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue_sim/main.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by a... | 5,531 | 40.283582 | 110 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue_sim/finetune_clue_sim.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by a... | 13,899 | 41.638037 | 114 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue_sim/loss.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by a... | 2,693 | 33.538462 | 117 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue_sim/__init__.py | 0 | 0 | 0 | py | |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/deepVAE/vae_pl_module.py | # coding=utf-8
# Copyright 2022 IDEA-CCNL The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
... | 14,840 | 52.193548 | 175 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/deepVAE/pretrain_deep_vae.py | import torch
import os
import random
import math
import argparse
from fengshen.data.fs_datasets.fs_datamodule import FSDataModule
from fengshen.example.deepVAE.vae_pl_module import DeepVAEModule
from pytorch_lightning import (
Trainer,
loggers,
)
from pytorch_lightning.callbacks import ModelCheckpoint, Learni... | 6,369 | 43.859155 | 126 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/unimc/example.py | import argparse
from fengshen.pipelines.multiplechoice import UniMCPipelines
def main():
total_parser = argparse.ArgumentParser("TASK NAME")
total_parser = UniMCPipelines.pipelines_args(total_parser)
args = total_parser.parse_args()
pretrained_model_path = 'IDEA-CCNL/Erlangshen-UniMC-RoBERTa-110M-Ch... | 1,963 | 22.380952 | 77 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/PPVAE/generate.py | import torch
from transformers import BertTokenizer,T5Tokenizer
from fengshen.models.PPVAE.pluginVAE import PPVAEModel
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
encoder_tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Randeng-PPVAE-1.2B-Augmentation-Chinese")
decoder_tokenizer = T5Token... | 1,807 | 74.333333 | 188 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pretrain_bert/pretrain_bert.py | from data.bert_dataloader.load import BertDataModule
from transformers import (
BertTokenizer,
BertConfig,
BertForPreTraining,
BertModel,
BertForMaskedLM
)
from pytorch_lightning import (
LightningDataModule,
LightningModule,
loggers,
Trainer,
)
from pytorch_lightning.callbacks impor... | 10,636 | 37.125448 | 100 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/metric/utils_ner.py | import csv
import json
import torch
from transformers import BertTokenizer
class CNerTokenizer(BertTokenizer):
def __init__(self, vocab_file, do_lower_case=True):
super().__init__(vocab_file=str(vocab_file), do_lower_case=do_lower_case)
self.vocab_file = str(vocab_file)
self.do_lower_case ... | 8,822 | 32.675573 | 110 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/metric/metric.py | # coding=utf-8
from collections import Counter
import torch
from torch import nn
# import seqeval
from .utils_ner import get_entities
class metrics_mlm_acc(nn.Module):
def __init__(self):
super().__init__()
def forward(self, logits, labels, masked_lm_metric):
# if len(list(logits.shape))==3... | 4,970 | 37.238462 | 111 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/model_utils.py | from pytorch_lightning import LightningModule
from pytorch_lightning.strategies import DeepSpeedStrategy
from deepspeed.ops.adam import DeepSpeedCPUAdam, FusedAdam
from transformers.optimization import AdamW, TYPE_TO_SCHEDULER_FUNCTION
from torch.optim import Optimizer
from torch.optim.lr_scheduler import _LRScheduler
... | 11,270 | 43.2 | 157 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/transformer_utils.py | 0 | 0 | 0 | py | |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/__init__.py | # coding=utf-8
| 15 | 7 | 14 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/bart/modeling_bart.py | import warnings
from pytorch_lightning import LightningModule
from fengshen.models import transformer_utils
import torch
import torch.utils.checkpoint
from torch import nn
import torch.nn.functional as F
from dataclasses import dataclass
from typing import Optional, Tuple
from transformers.file_utils import *
from t... | 17,777 | 40.929245 | 149 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/DAVAE/run_latent_generation.py | import re
import torch
import torch.nn.functional as F
from torch.nn.utils.rnn import pad_sequence
import numpy as np
import json
import jsonlines
from tqdm import tqdm, trange
def set_seed(args):
np.random.seed(args.seed)
torch.manual_seed(args.seed)
if args.n_gpu > 0:
torch.cuda.manual_seed_all(a... | 13,632 | 43.993399 | 212 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/DAVAE/BertForLatentConnector.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 7,251 | 51.550725 | 134 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/DAVAE/DAVAEModel.py | import os
import torch
import torch.nn as nn
import torch.nn.functional as F
from transformers import BertConfig,TransfoXLConfig
from transformers.configuration_utils import PretrainedConfig
from transformers.modeling_utils import PreTrainedModel
from transformers.utils import cached_path,hf_bucket_url
from fengshen.mo... | 10,280 | 42.563559 | 186 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/DAVAE/GPT2ModelForLatent.py | # coding=utf-8
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless re... | 27,514 | 41.925117 | 139 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/DAVAE/__init__.py | # coding=utf-8
# Copyright 2022 IDEA-CCNL The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
... | 665 | 40.625 | 74 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/clip/configuration_taiyi_clip.py | # coding=utf-8
# Copyright 2021 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless r... | 7,069 | 37.423913 | 118 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/clip/processing_taiyi_clip.py | # coding=utf-8
# Copyright 2022 The OFA-Sys Team Authors and The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/... | 5,784 | 48.87069 | 136 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/clip/modeling_taiyi_clip.py | import torch
from torch import nn
from transformers import BertTokenizer
from transformers.models.clip.modeling_clip import (
add_start_docstrings,
add_start_docstrings_to_model_forward,
CLIP_START_DOCSTRING,
CLIP_TEXT_INPUTS_DOCSTRING,
CLIP_VISION_INPUTS_DOCSTRING,
CLIP_INPUTS_DOCSTRING,
re... | 11,583 | 39.362369 | 117 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/clip/__init__.py | from .modeling_taiyi_clip import TaiyiCLIPModel, TaiyiCLIPEmbedder
from .processing_taiyi_clip import TaiyiCLIPProcessor
__all__ = ['TaiyiCLIPModel', 'TaiyiCLIPProcessor', 'TaiyiCLIPEmbedder']
| 194 | 38 | 71 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/longformer/modeling_longformer.py | # coding=utf-8
# Copyright 2020 The Allen Institute for AI team and The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2... | 118,901 | 46.82864 | 222 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/longformer/tokenization_longformer.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by a... | 677 | 38.882353 | 74 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/longformer/configuration_longformer.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by a... | 657 | 37.705882 | 74 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/longformer/__init__.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by a... | 1,823 | 31.571429 | 91 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/bert_for_tagging.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from .layers.crf import CRF
from .layers.bert_output import BiaffineClassifierOutput, TokenClassifierOutput, SpanClassifierOutput
from transformers import BertPreTrainedModel
from transformers import BertModel
from .layers.linears import PoolerEndLogit... | 9,885 | 47.460784 | 147 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/layers/linears.py | import torch
import torch.nn as nn
import torch.nn.functional as F
class FeedForwardNetwork(nn.Module):
def __init__(self, input_size, hidden_size, output_size, dropout_rate=0):
super(FeedForwardNetwork, self).__init__()
self.dropout_rate = dropout_rate
self.linear1 = nn.Linear(input_size, ... | 2,701 | 39.328358 | 102 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/layers/bert_output.py | import torch
from dataclasses import dataclass
from typing import Optional
@dataclass
class TokenClassifierOutput:
"""
Base class for outputs of token classification models.
"""
loss: Optional[torch.FloatTensor] = None
logits: torch.FloatTensor = None
@dataclass
class SpanClassifierOutput:
""... | 721 | 22.290323 | 58 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/layers/crf.py | import torch
import torch.nn as nn
from typing import List, Optional
class CRF(nn.Module):
"""Conditional random field.
This module implements a conditional random field [LMP01]_. The forward computation
of this class computes the log likelihood of the given sequence of tags and
emission score tensor. ... | 19,972 | 47.596107 | 99 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/losses/label_smoothing.py | import torch.nn as nn
import torch.nn.functional as F
class LabelSmoothingCrossEntropy(nn.Module):
def __init__(self, eps=0.1, reduction='mean',ignore_index=-100):
super(LabelSmoothingCrossEntropy, self).__init__()
self.eps = eps
self.reduction = reduction
self.ignore_index = ignore... | 841 | 39.095238 | 103 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.