学习笔记系列文章总录
huggingface简单入门 huggingface简单入门(一)简介与安装 huggi …
huggingface简单入门 huggingface简单入门(一)简介与安装 huggi …
什么是Monad Monad接受一个普通的函数,这个普通函数接受一个普通值并返回一个普通值 …
美化内容: 更换Terminal Emulator 安装配置Powershell插件 PS …
定义数据集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import torch from datasets import load_dataset import random #定义数据集 class Dataset(torch.utils.data.Dataset): def __init__(self, split): dataset = load_dataset(path='seamew/ChnSentiCorp', split=split) def f(data): return len(data['text']) > 40 self.dataset = dataset.filter(f) def __len__(self): return len(self.dataset) def __getitem__(self, i): text = self.dataset[i]['text'] #切分一句话为前半句和后半句 sentence1 = text[:20] sentence2 = text[20:40] label = 0 #有一半的概率把后半句替换为一句无关的话 if random.randint(0, 1) == 0: j = random.randint(0, len(self.dataset) - 1) sentence2 = self.dataset[j]['text'][20:40] label = 1 return sentence1, sentence2, label dataset = Dataset('train') sentence1, sentence2, label = dataset[0] len(dataset), sentence1, sentence2, label # (8001, '选择珠江花园的原因就是方便,有电动扶梯直', '接到达海边,周围餐馆、食廊、商场、超市、', 0) |
加载字典和分 …
定义数据集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import torch from datasets import load_dataset #定义数据集 class Dataset(torch.utils.data.Dataset): def __init__(self, split): dataset = load_dataset(path='seamew/ChnSentiCorp', split=split) def f(data): return len(data['text']) > 30 # 过滤,只需要大于30个字符的数据 self.dataset = dataset.filter(f) def __len__(self): return len(self.dataset) def __getitem__(self, i): text = self.dataset[i]['text'] return text dataset = Dataset('train') len(dataset), dataset[0] #(9192, # '选择珠江花园的原因就是方便,有电动扶梯直接到达海边,周围餐馆、食廊、商场、超市、摊位一应俱全。酒店装修一般,但还算整洁。 泳池在大堂的屋顶,因此很小,不过女儿倒是喜欢。 包的早餐是西式的,还算丰富。 服务吗,一般') |
加载字典和分 …
定义数据集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import torch from datasets import load_dataset #定义数据集 class Dataset(torch.utils.data.Dataset): def __init__(self, split): self.dataset = load_dataset(path='seamew/ChnSentiCorp', split=split) def __len__(self): return len(self.dataset) def __getitem__(self, i): text = self.dataset[i]['text'] label = self.dataset[i]['label'] return text, label dataset = Dataset('train') len(dataset), dataset[0] # (9600, # ('选择珠江花园的原因就是方便,有电动扶梯直接到达海边,周围餐馆、食廊、商场、超市、摊位一应俱全。酒店装修一般,但还算整洁。 泳池在大堂的屋顶,因此很小,不过女儿倒是喜欢。 包的早餐是西式的,还算丰富。 服务吗,一般', # 1)) |
加载字典和分 …
可以使用pipeline 来解决一些简单的任务。不实用,专业价值不高。 情感分析 [cra …
查看可用的评价指标
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
from datasets import list_metrics #列出评价指标 metrics_list = list_metrics() len(metrics_list), metrics_list # (41, # ['accuracy', # 'bertscore', # 'bleu', # 'bleurt', # 'cer', # 'chrf', # 'code_eval', # 'comet', # 'competition_math', # 'coval', # 'cuad', # 'f1', # 'frugalscore', # 'gleu', # 'glue', # 'google_bleu', # 'indic_glue', # 'mae', # 'mahalanobis', # 'matthews_correlation', # 'mauve', # 'mean_iou', # 'meteor', # 'mse', # 'pearsonr', # 'perplexity', # 'precision', # 'recall', # 'rouge', # 'sacrebleu', # 'sari', # 'seqeval', # 'spearmanr', # 'squad', # 'squad_v2', # 'super_glue', # 'ter', # 'wer', # 'wiki_split', # 'xnli', # 'xtreme_s']) |
使用 …
加载数据
1 2 3 4 5 6 7 8 9 10 11 12 |
from datasets import load_dataset #加载数据 dataset = load_dataset(path='seamew/ChnSentiCorp', split='train') dataset # Dataset({ # features: ['text', 'label'], # num_rows: 9600 # }) |
数据集可以通过 …
分词 加载 tokenizer 准备预料 [crayon-62bd809237432991 …
什么是huggingface ? Huggingface 是一个开源社区, 它提供了先进的 …