我正在使用 spacy 版本 3 进行一些性能测试,以便在生产中调整实例的大小。我正在观察以下情况
观察:
| 型号名称 | 没有 NER 的时间 | 与 NER 共度时光 | 评论 |
|---|---|---|---|
| en_core_web_lg | 4.89秒 | 21.9秒 | NER在原来的基础上增加了350% |
| en_core_web_trf | 43.64秒 | 52.83秒 | NER 只比原来的时间增加了 20% |
为什么在使用 Transformer 模型的情况下,使用 NER和不使用 NER 的情况没有显着差异?在 en_core_web_trf 的情况下,NER 是否只是 POS 标记之后的增量任务?
测试环境: GPU实例
测试代码:
import spacy
assert(spacy.__version__ == '3.0.3')
spacy.require_gpu()
texts = load_sample_texts() # loads 10,000 texts from a file
assert(len(texts) == 10000)
def get_execution_time(nlp, texts, N):
return timeit.timeit(stmt="[nlp(text) for text in texts]",
globals={'nlp': nlp, 'texts': texts}, number=N) / N
# load …Run Code Online (Sandbox Code Playgroud) 我来这里是想问你们是否可以将现有的经过训练的 Huggingface-transformers 模型与 spacy 一起使用。
我的第一个天真的尝试是通过加载它spacy.load('bert-base-uncased'),它不起作用,因为 spacy 需要一定的结构,这是可以理解的。
现在我试图弄清楚如何使用该spacy-transformers库来加载模型,创建 spacy 结构,并从那时起将其用作正常的 spacy 感知模型。
我不知道这是否可能,因为我找不到有关该主题的任何信息。我尝试阅读文档,但我发现的所有指南、示例和帖子都是从 spacy/en_core_web_sm 这样的 spacy 结构化模型开始的,但该模型最初是如何创建的?我相信有人必须用 spacy 重新训练一切。
我可以向你寻求帮助吗?
谢谢。
spacy bert-language-model spacy-transformers huggingface-transformers
我正在尝试让 pytorch 模型在句子分类任务上运行。在处理医疗笔记时,我正在使用 ClinicalBert ( https://github.com/kexinhuang12345/clinicalBERT ) 并希望使用其预先训练的权重。不幸的是,ClinicalBert 模型只将文本分类为 1 个二进制标签,而我有 281 个二进制标签。因此,我试图实现此代码https://github.com/kaushaltrivedi/bert-toxic-comments-multilabel/blob/master/toxic-bert-multilabel-classification.ipynb,其中 bert 之后的最终分类器长度为 281。
如何在不加载分类权重的情况下从 ClinicalBert 模型加载预训练的 Bert 权重?
天真地尝试从预训练的 ClinicalBert 权重中加载权重,我收到以下错误:
size mismatch for classifier.weight: copying a param with shape torch.Size([2, 768]) from checkpoint, the shape in current model is torch.Size([281, 768]).
size mismatch for classifier.bias: copying a param with shape torch.Size([2]) from checkpoint, the shape in current model is torch.Size([281]).
Run Code Online (Sandbox Code Playgroud)
我目前尝试从 pytorch_pretrained_bert 包中替换 from_pretrained 函数,并像这样弹出分类器权重和偏差:
def from_pretrained(cls, pretrained_model_name, state_dict=None, cache_dir=None, *inputs, **kwargs):
...
if …Run Code Online (Sandbox Code Playgroud) python machine-learning pre-trained-model pytorch spacy-transformers
使用 spacy v3,我尝试使用camemBert 训练分类器,但遇到了CUDA out of memory问题。为了解决这个问题,我读到应该减小批量大小,但我很困惑应该更改哪个参数:
我试图理解每个参数之间的区别:
管道和评估的默认批量大小。默认为 1000。
培训/评估过程中是否使用了这些功能?
在快速启动小部件(https://spacy.io/usage/training#quickstart)中,为什么该值根据硬件而不同?CPU 为 1000,GPU 为 128。
训练过程中,这个值低的话评估会不会慢一些?
填充批次的最大尺寸。默认为 4096。
根据警告消息:Token indices sequence length is longer than the specified maximum sequence length for this model (556 > 512). Running this sequence through the model will result in indexing errors此处解释(https://github.com/explosion/spaCy/issues/6939),Camembert模型指定的最大序列长度为 512。
参数 max_batch_item 是否重载到该值?我应该将该值更改为 512 吗?
machine-learning spacy-transformers huggingface-transformers spacy-3
我正在尝试将我的 spacy 版本升级到每晚,特别是为了使用 spacy 变压器
\n所以我转换了spacy简单的火车数据集,其格式如下
\ntd = [["Who is Shaka Khan?", {"entities": [(7, 17, "FRIENDS")]}],["I like London.", {"entities": [(7, 13, "LOC")]}],]
以上至
\n[[{"head": 0, "dep": "", "tag": "", "orth": "Who", "ner": "O", "id": 0}, {"head": 0, "dep": "", "tag": "", "orth": "is", "ner": "O", "id": 1}, {"head": 0, "dep": "", "tag": "", "orth": "Shaka", "ner": "B-FRIENDS", "id": 2}, {"head": 0, "dep": "", "tag": "", "orth": "Khan", "ner": "L-FRIENDS", "id": 3}, {"head": 0, "dep": "", "tag": …
如何从 Huggingface 的特征提取管道中获取整个句子的嵌入?
我了解如何获取每个标记的特征(如下),但如何获取整个句子的总体特征?
feature_extraction = pipeline('feature-extraction', model="distilroberta-base", tokenizer="distilroberta-base")
features = feature_extraction("i am sentence")
Run Code Online (Sandbox Code Playgroud) nlp machine-learning spacy-transformers huggingface-transformers