id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
20,694
import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb import torch.nn as nn import torch import torch.optim as optim from torch.utils.data i...
单条样本推理
20,695
from bert4torch.tokenizers import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb import torch.nn as nn import torch import torch.optim as op...
null
20,696
from bert4torch.tokenizers import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb import torch.nn as nn import torch import torch.optim as op...
null
20,697
import torch import torch.nn as nn import numpy as np from bert4torch.tokenizers import Tokenizer from bert4torch.models import build_transformer_model from torch.optim import Adam import torch.nn.functional as F from bert4torch.snippets import sequence_padding, ListDataset from bert4torch.callbacks import Callback fro...
null
20,698
import torch import torch.nn as nn import numpy as np from bert4torch.tokenizers import Tokenizer from bert4torch.models import build_transformer_model from torch.optim import Adam import torch.nn.functional as F from bert4torch.snippets import sequence_padding, ListDataset from bert4torch.callbacks import Callback fro...
对输入进行随机mask
20,699
ers import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset import torch.nn as nn import torch import torch.optim as optim from torch.utils.data import DataLoader, Dataset m...
null
20,700
ers import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset import torch.nn as nn import torch import torch.optim as optim from torch.utils.data import DataLoader, Dataset m...
null
20,701
import numpy as np from bert4torch.tokenizers import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb import torch.nn as nn import torch impor...
null
20,702
import numpy as np from bert4torch.tokenizers import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb import torch.nn as nn import torch impor...
null
20,703
from bert4torch.tokenizers import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb import torch.nn as nn import torch import torch.optim as op...
null
20,704
from bert4torch.tokenizers import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb import torch.nn as nn import torch import torch.optim as op...
null
20,705
import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader from bert4torch.models import build_transformer_model from bert4torch.generation import AutoRegressiveDecoder from bert4torch.snippets import ListDataset, sequence_padding from bert4torch.callbacks import Callback fro...
[ ['哈哈', '哦', '你是猪', '不是'] ] [CLS]text1[SEP]text2[SEP]
20,706
import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader from bert4torch.models import build_transformer_model from bert4torch.generation import AutoRegressiveDecoder from bert4torch.snippets import ListDataset, sequence_padding from bert4torch.callbacks import Callback fro...
null
20,707
import torch.optim as optim import json from torch.utils.data import DataLoader from bert4torch.models import build_transformer_model from bert4torch.tokenizers import SpTokenizer from bert4torch.generation import AutoRegressiveDecoder from bert4torch.snippets import sequence_padding, ListDataset from bert4torch.callba...
格式为:
20,708
import torch.optim as optim import json from torch.utils.data import DataLoader from bert4torch.models import build_transformer_model from bert4torch.tokenizers import SpTokenizer from bert4torch.generation import AutoRegressiveDecoder from bert4torch.snippets import sequence_padding, ListDataset from bert4torch.callba...
null
20,709
The provided code snippet includes necessary dependencies for implementing the `collate_fn` function. Write a Python function `def collate_fn(batch)` to solve the following problem: 单条样本格式:content:[CLS]文章[SEP] tgt: [CLS]标题[SEP] Here is the function: def collate_fn(batch): """单条样本格式:content:[CLS]文章[SEP] tgt: [C...
单条样本格式:content:[CLS]文章[SEP] tgt: [CLS]标题[SEP]
20,710
def just_show(): s1 = u'抽象了一种基于中心的战术应用场景与业务,并将网络编码技术应用于此类场景的实时数据多播业务中。在分析基于中心网络与Many-to-all业务模式特性的基础上,提出了仅在中心节点进行编码操作的传输策略以及相应的贪心算法。分析了网络编码多播策略的理论增益上界,仿真试验表明该贪心算法能够获得与理论相近的性能增益。最后的分析与仿真试验表明,在这种有中心网络的实时数据多播应用中,所提出的多播策略的实时性能要明显优于传统传输策略。' s2 = u'普适计算环境中未知移动节点的位置信息是定位服务要解决的关键技术。在普适计算二维空间定位过程中,通过对三角形定位单元区域的误差分析,提出...
null
20,711
h.models import build_transformer_model, BaseModel from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, seed_everything, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback import torch import torch.nn as nn i...
单条样本格式:content:[CLS]文章[SEP] tgt: [CLS]标题[SEP]
20,712
h.models import build_transformer_model, BaseModel from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, seed_everything, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback import torch import torch.nn as nn i...
null
20,713
The provided code snippet includes necessary dependencies for implementing the `collate_fn` function. Write a Python function `def collate_fn(batch)` to solve the following problem: 单条样本格式:[CLS]文章[SEP]标题[SEP] Here is the function: def collate_fn(batch): """单条样本格式:[CLS]文章[SEP]标题[SEP] """ batch_token_ids,...
单条样本格式:[CLS]文章[SEP]标题[SEP]
20,715
os from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding from bert4torch.snippets import ListDataset from bert4torch.callbacks import Callback from tqdm import tqdm import torch from torchinfo import summary import ...
null
20,716
from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding from bert4torch.snippets import ListDataset from bert4torch.callbacks import Callback from tqdm import tqdm import torch from torchinfo import summary import tor...
单条样本格式为 输入: [CLS][MASK][MASK][SEP]问题[SEP]篇章[SEP] 输出: 答案
20,717
from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding from bert4torch.snippets import ListDataset from bert4torch.callbacks import Callback from tqdm import tqdm import torch from torchinfo import summary import tor...
将预测结果输出到文件,方便评估
20,718
t4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback import torch from torchinfo import summar...
单条样本格式:[CLS]篇章[SEP]答案[SEP]问题[SEP]
20,719
t4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback import torch from torchinfo import summar...
null
20,720
import numpy as np import torch from torch import nn, optim from torch.utils.data import DataLoader import torch.nn.functional as F from bert4torch.models import build_transformer_model, BaseModel from bert4torch.snippets import sequence_padding, ListDataset, text_segmentate, get_pool_emb from bert4torch.generation imp...
null
20,721
import numpy as np import torch from torch import nn, optim from torch.utils.data import DataLoader import torch.nn.functional as F from bert4torch.models import build_transformer_model, BaseModel from bert4torch.snippets import sequence_padding, ListDataset, text_segmentate, get_pool_emb from bert4torch.generation imp...
随机观察一些样本的效果
20,722
import division import json, re from tqdm import tqdm from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from torch import nn, optim import torch from torch.utils.data import DataLoader from bert4torch.callbacks import Callback from bert4torch.snippets import s...
去掉冗余的括号
20,723
import division import json, re from tqdm import tqdm from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from torch import nn, optim import torch from torch.utils.data import DataLoader from bert4torch.callbacks import Callback from bert4torch.snippets import s...
null
20,724
import numpy as np from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer import torch.optim as optim import torch.nn as nn import torch import torch.nn.functional as F from torch.utils.data import DataLoader from bert4torch.snippets import ListDataset, sequence_padding from b...
最长公共子序列(source和target的最长非连续子序列) 返回:子序列长度, 映射关系(映射对组成的list) 注意:最长公共子序列可能不止一个,所返回的映射只代表其中一个。
20,725
s, json import numpy as np from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer import torch.optim as optim import torch.nn as nn import torch import torch.nn.functional as F from torch.utils.data import DataLoader from bert4torch.snippets import ListDataset, sequence_paddin...
读取数据集
20,726
import numpy as np from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer import torch.optim as optim import torch.nn as nn import torch import torch.nn.functional as F from torch.utils.data import DataLoader from bert4torch.snippets import ListDataset, sequence_padding from b...
数据生成器 单条样本:[CLS] Q [SEP] S [SEP] P [SEP] M [SEP]
20,727
s, json import numpy as np from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer import torch.optim as optim import torch.nn as nn import torch import torch.nn.functional as F from torch.utils.data import DataLoader from bert4torch.snippets import ListDataset, sequence_paddin...
输出测试结果到文件 结果文件可以提交到 https://www.cluebenchmarks.com 评测。
20,730
os from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback from tqdm import tqdm import t...
null
20,731
from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback from tqdm import tqdm import torc...
单条样本格式: [CLS]篇章[SEP]问题[SEP]答案[SEP]
20,732
from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback from tqdm import tqdm import torc...
将预测结果输出到文件,方便评估
20,733
t4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback import torch from torchinfo import summar...
单条样本格式:[CLS]篇章[SEP]答案[SEP]问题[SEP]
20,734
t4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback import torch from torchinfo import summar...
null
20,735
json, os from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback from tqdm import tqdm i...
null
20,736
from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback from tqdm import tqdm import tor...
单条样本格式:[CLS]篇章[SEP]答案[SEP]问题[SEP]
20,737
from bert4torch.models import build_transformer_model from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset from bert4torch.generation import AutoRegressiveDecoder from bert4torch.callbacks import Callback from tqdm import tqdm import tor...
将预测结果输出到文件,方便评估
20,738
The provided code snippet includes necessary dependencies for implementing the `collate_fn` function. Write a Python function `def collate_fn(batch)` to solve the following problem: 单条样本格式:content:[CLS]文章[SEP] tgt: [CLS]标题[SEP] Here is the function: def collate_fn(batch): """单条样本格式:content:[CLS]文章[SEP] tgt: [C...
单条样本格式:content:[CLS]文章[SEP] tgt: [CLS]标题[SEP]
20,740
import torch from torch.utils.data import DataLoader from model import uie_model, tokenizer, custom_model from bert4torch.snippets import seed_everything, sequence_padding from bert4torch.callbacks import Callback from torch import nn from torch.utils.data import Dataset import json from utils import get_bool_ids_great...
example: {title, prompt, content, result_list}
20,741
import contextlib import functools import json import logging import math import random import re import shutil import threading import time from functools import partial import colorlog import numpy as np import torch from colorama import Back, Fore from tqdm import tqdm The provided code snippet includes necessary d...
Get span set from position start and end list. Args: start_ids (List[int]/List[tuple]): The start index list. end_ids (List[int]/List[tuple]): The end index list. with_prob (bool): If True, each element for start_ids and end_ids is a tuple aslike: (index, probability). Returns: set: The span set without overlapping, ev...
20,742
import contextlib import functools import json import logging import math import random import re import shutil import threading import time from functools import partial import colorlog import numpy as np import torch from colorama import Back, Fore from tqdm import tqdm The provided code snippet includes necessary d...
Get idx of the last dimension in probability arrays, which is greater than a limitation. Args: probs (List[List[float]]): The input probability arrays. limit (float): The limitation for probability. return_prob (bool): Whether to return the probability Returns: List[List[int]]: The index of the last dimension meet the ...
20,743
import contextlib import functools import json import logging import math import random import re import shutil import threading import time from functools import partial import colorlog import numpy as np import torch from colorama import Back, Fore from tqdm import tqdm def get_id_and_prob(spans, offset_map): pr...
null
20,744
import contextlib import functools import json import logging import math import random import re import shutil import threading import time from functools import partial import colorlog import numpy as np import torch from colorama import Back, Fore from tqdm import tqdm The provided code snippet includes necessary d...
Cut the Chinese sentences more precisely, reference to "https://blog.csdn.net/blmoistawinde/article/details/82379256".
20,745
import contextlib import functools import json import logging import math import random import re import shutil import threading import time from functools import partial import colorlog import numpy as np import torch from colorama import Back, Fore from tqdm import tqdm def dbc2sbc(s): rs = "" for char in s:...
null
20,746
import contextlib import functools import json import logging import math import random import re import shutil import threading import time from functools import partial import colorlog import numpy as np import torch from colorama import Back, Fore from tqdm import tqdm logger = Logger() tqdm = partial(tqdm, bar_form...
Download from given url to root_dir. if file or directory specified by url is exists under root_dir, return the path directly, otherwise download from url and decompress it, return the path. Args: url (str): download url root_dir (str): root dir for downloading, it should be WEIGHTS_HOME or DATASET_HOME decompress (boo...
20,747
import re import json en2ch = { 'ORG':'机构', 'PER':'人名', 'LOC':'籍贯' } def preprocess(input_path, save_path, mode): if not os.path.exists(save_path): os.makedirs(save_path) data_path = os.path.join(save_path, mode + ".json") result = [] tmp = {} tmp['id'] = 0 tmp['text'] = '' ...
null
20,748
import time import argparse import json from decimal import Decimal import numpy as np from bert4torch.snippets import seed_everything from utils import convert_ext_examples, convert_cls_examples, logger logger = Logger() def convert_cls_examples(raw_examples, prompt_prefix, options): examples = [] ...
null
20,749
import numpy as np from bert4torch.models import build_transformer_model, BaseModel import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4to...
null
20,750
import numpy as np from bert4torch.models import build_transformer_model, BaseModel import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4to...
null
20,751
import numpy as np from bert4torch.models import build_transformer_model, BaseModel import torch from torch.utils.data import DataLoader import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.tokenizers import ...
null
20,752
import numpy as np from bert4torch.models import build_transformer_model, BaseModel import torch from torch.utils.data import DataLoader import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.tokenizers import ...
null
20,753
import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer from bert4torch.mo...
null
20,754
import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer from bert4torch.mo...
null
20,755
import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer from bert4torch.mo...
null
20,756
import numpy as np from bert4torch.models import build_transformer_model, BaseModel import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4to...
把第i行,第j列转化成上三角flat后的序号
20,757
import numpy as np from bert4torch.models import build_transformer_model, BaseModel import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4to...
获取最后一个分类层的的映射关系
20,758
import numpy as np from bert4torch.models import build_transformer_model, BaseModel import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4to...
null
20,759
import numpy as np from bert4torch.models import build_transformer_model, BaseModel import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4to...
null
20,760
def collate_fn(batch): batch_token_ids, batch_labels, batch_entity_ids, batch_entity_labels = [], [], [], [] for d in batch: tokens = tokenizer.tokenize(d[0], maxlen=maxlen) mapping = tokenizer.rematch(d[0], tokens) start_mapping = {j[0]: i for i, j in enumerate(mapping) if j} ...
null
20,761
import numpy as np import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer...
null
20,762
import numpy as np import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer...
null
20,763
import numpy as np import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer...
null
20,764
import numpy as np import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer...
null
20,765
import numpy as np import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer...
null
20,766
import numpy as np import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer...
null
20,767
import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer from bert4torch.mo...
加载数据 单条格式:[词1, 词2, 词3, ...]
20,768
import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer from bert4torch.mo...
标签含义 0: 单字词; 1: 多字词首字; 2: 多字词中间; 3: 多字词末字
20,769
import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer from bert4torch.mo...
null
20,770
import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer from bert4torch.mo...
简单的评测 该评测指标不等价于官方的评测指标,但基本呈正相关关系, 可以用来快速筛选模型。
20,771
import torch from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.layers import CRF from bert4torch.tokenizers import Tokenizer from bert4torch.mo...
预测结果到文件,便于用官方脚本评测 使用示例: predict_to_file('/root/icwb2-data/testing/pku_test.utf8', 'myresult.txt') 官方评测代码示例: data_dir="/root/icwb2-data" $data_dir/scripts/score $data_dir/gold/pku_training_words.utf8 $data_dir/gold/pku_test_gold.utf8 myresult.txt > myscore.txt (执行完毕后查看myscore.txt的内容末尾)
20,772
import torch import torch.nn.functional as F from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.optimizers import get_linear_schedule_with_warmu...
null
20,773
import torch import torch.nn.functional as F from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.optimizers import get_linear_schedule_with_warmu...
null
20,774
import torch import torch.nn.functional as F from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.optimizers import get_linear_schedule_with_warmu...
null
20,775
def collate_fn(batch): batch_token_ids, batch_start_labels, batch_end_labels = [], [], [] for d in batch: tokens = tokenizer.tokenize(d[0], maxlen=max_len)[1:] # 不保留[CLS] mapping = tokenizer.rematch(d[0], tokens) start_mapping = {j[0]: i for i, j in enumerate(mapping) if j} en...
null
20,776
def evaluate(data): X, Y, Z = 0, 1e-10, 1e-10 for token_ids, labels in tqdm(data, desc='Evaluation'): start_logit, end_logit = model.predict(token_ids) # [btz, seq_len, 2] mask, start_ids, end_ids = labels # entity粒度 entity_pred = span_decode(start_logit, end_logit, mask) ...
null
20,777
import numpy as np import torch import torch.nn.functional as F from torch.utils.data import DataLoader import torch.nn as nn from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, ListDataset, seed_everything from bert4torch.optimizers import get_linear_schedule_with_warmup from be...
null
20,778
def collate_fn(batch): batch_token_ids, batch_start_labels, batch_end_labels = [], [], [] for d in batch: tokens = tokenizer.tokenize(d[0], maxlen=max_c_len) mapping = tokenizer.rematch(d[0], tokens) start_mapping = {j[0]: i for i, j in enumerate(mapping) if j} end_mapping = {j...
null
20,779
def evaluate(data): X, Y, Z = 0, 1e-10, 1e-10 for inputs, labels in tqdm(data, desc='Evaluation'): start_logit, end_logit, span_logits = model.predict(inputs) mask, start_labels, end_labels, span_labels = labels # entity粒度 entity_pred = decode(start_logit, end_logit, mask) ...
null
20,780
def collate_fn(batch): batch_token_ids, batch_segment_ids, batch_start_labels, batch_end_labels = [], [], [], [] batch_ent_type = [] for d in batch: tokens_b = tokenizer.tokenize(d[0], maxlen=max_c_len)[1:] # 不保留[CLS] mapping = tokenizer.rematch(d[0], tokens_b) start_mapping = {j[...
null
20,781
def evaluate(data): X, Y, Z = 0, 1e-10, 1e-10 for (token_ids, segment_ids), labels in tqdm(data, desc='Evaluation'): start_logit, end_logit = model.predict([token_ids, segment_ids]) # [btz, seq_len, 2] mask, start_ids, end_ids, ent_type = labels # entity粒度 entity_pred = mrc_d...
null
20,782
import argparse import json import pandas as pd from tqdm import tqdm from model import BertClient def create_document(doc, emb, index_name): return { '_op_type': 'index', '_index': index_name, 'text': doc['text'], 'title': doc['title'], 'text_vector': emb }
null
20,783
import argparse import json import pandas as pd from tqdm import tqdm from model import BertClient def load_dataset(path): docs = [] df = pd.read_csv(path, encoding='utf-8') for row in df.iterrows(): series = row[1] doc = { 'title': series.Title, 'text': series.Descr...
null
20,784
import argparse import json import pandas as pd from tqdm import tqdm from model import BertClient bc = BertClient(batch_size=128, use_tqdm=False) The provided code snippet includes necessary dependencies for implementing the `bulk_predict` function. Write a Python function `def bulk_predict(docs, batch_size=256)` to ...
Predict bert embeddings.
20,785
import argparse import json from elasticsearch import Elasticsearch from elasticsearch.helpers import bulk def load_dataset(path): with open(path, 'r', encoding='utf-8') as f: return [json.loads(line) for line in f]
null
20,786
import os from pprint import pprint from flask import Flask, render_template, jsonify, request from elasticsearch import Elasticsearch from src.model import BertClient SEARCH_SIZE = 10 INDEX_NAME = 'jobsearch' def index(): return render_template('index.html') " = class BertClient(object): def __init__(self, ...
null
20,787
from bert4torch.tokenizers import Tokenizer from bert4torch.snippets import sequence_padding import numpy as np def preprocess(text_list): batch_token_ids, batch_segment_ids = [], [] for text in text_list: token_ids, segment_ids = tokenizer.encode(text, maxlen=512) batch_token_ids.append(token_...
null
20,788
from bert4torch.tokenizers import Tokenizer from bert4torch.snippets import sequence_padding import numpy as np The provided code snippet includes necessary dependencies for implementing the `postprocess` function. Write a Python function `def postprocess(res)` to solve the following problem: 后处理 Here is the function...
后处理
20,789
numpy as np import torch import torch.nn as nn from bert4torch.snippets import get_pool_emb from bert4torch.tokenizers import Tokenizer from bert4torch.models import build_transformer_model, BaseModel import time from tqdm import tqdm def to_numpy(tensor): return tensor.detach().cpu().numpy() if tensor.requires_gr...
null
20,790
from bert4torch.models import build_transformer_model, BaseModel from bert4torch.snippets import sequence_padding, get_pool_emb from bert4torch.generation import AutoRegressiveDecoder from bert4torch.tokenizers import Tokenizer, load_vocab from bert4torch.snippets import WebServing synonyms_generator = SynonymsGenerat...
含义: 产生sent的n个相似句,然后返回最相似的k个。 做法:用seq2seq生成,并用encoder算相似度并排序。
20,791
import logging import logging.config from typing import Optional, Text from src.utils.configs import Configuration TRACE_LOG = "tracelogger" def get_trace_log(): return logging.getLogger(TRACE_LOG)
null
20,792
import json def send_msg(requestData): url = 'http://localhost:8082/recommendinfo' headers = {'content-type': 'application/json'} ret = requests.post(url, json=requestData, headers=headers, stream=True) if ret.status_code==200: text = json.loads(ret.text) return text
null
20,793
from sanic import Sanic from typing import Optional, Text import src.config.constants as constants import src.utils.loggers as loggers import json def create_app(confs: Optional[Text] = None): def start_server(confs: Optional[Text] = None, port: int = constants.DEFAULT_SERVER_PORT): server = create_app(confs) ...
null
20,794
from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb from bert4torch.losses import UDALoss import torch.nn as nn import torch import torch.optim as optim fr...
null
20,795
import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb import torch.nn as nn import torch import torch.optim as optim from torch.utils.data i...
null
20,796
import Tokenizer from bert4torch.models import build_transformer_model, BaseModel from bert4torch.callbacks import Callback from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb import torch.nn as nn import torch import torch.optim as optim from torch.utils.data i...
单条样本推理
20,797
from bert4torch.tokenizers import Tokenizer from bert4torch.models import build_transformer_model, DeepSpeedTrainer from bert4torch.callbacks import Callback, Logger from bert4torch.snippets import sequence_padding, text_segmentate, ListDataset, seed_everything, get_pool_emb import torch.nn as nn import torch import to...
null