标签: ner

用 SpaCy 中的标签替换实体

无论如何,SpaCy 是否可以用其标签替换 SpaCy NER 检测到的实体?例如: 我在玩我的 Apple Macbook 时正在吃一个苹果。

我已经用 SpaCy 训练了 NER 模型来检测“水果”实体,并且该模型成功地将第一个“苹果”检测为“水果”,而不是第二个“苹果”。

我想通过用标签替换每个实体来对我的数据进行后处理,所以我想用“水果”替换第一个“苹果”。句子将是“我在玩我的 Apple Macbook 时正在吃水果。

如果我只是使用正则表达式,它也会用“FRUITS”替换第二个“Apple”,这是不正确的。有什么聪明的方法可以做到这一点吗?

谢谢!

nlp named-entity-recognition spacy ner

10
推荐指数
2
解决办法
2925
查看次数

我如何使用 spacy3.0 的 nlp.update 问题示例

我正在尝试使用 spacy v3.0 训练我的数据,显然 nlp.update 不接受任何元组。这是一段代码:

import spacy
import random
import json
nlp = spacy.blank("en")
ner = nlp.create_pipe("ner")
nlp.add_pipe('ner')
ner.add_label("label")
# Start the training
nlp.begin_training()
# Loop for 40 iterations
for itn in range(40):
    # Shuffle the training data
    random.shuffle(TRAINING_DATA)
    losses = {}
# Batch the examples and iterate over them
    for batch in spacy.util.minibatch(TRAINING_DATA, size=2):
        texts = [text for text, entities in batch]
        annotations = [entities for text, entities in batch]
# Update the model
        nlp.update(texts, annotations, losses=losses, drop=0.3) …
Run Code Online (Sandbox Code Playgroud)

nlp named-entity-recognition spacy ner

10
推荐指数
3
解决办法
3290
查看次数

如何在 Tensorflow 2 中使用 CRF 层(使用 tfa.text)?

model= Sequential()
model.add(keras.layers.Embedding(vocab_size,output_dim=100,input_length=input_len,weights=[embedding_matrix],trainable=False))
model.add(keras.layers.Bidirectional(keras.layers.LSTM(512, return_sequences=True,recurrent_dropout=0.2, dropout=0.2)))
model.add(keras.layers.Bidirectional(keras.layers.LSTM(512, return_sequences=True,recurrent_dropout=0.2, dropout=0.2)))

model.add(keras.layers.Dense(128, activation="relu"))

model.add(keras.layers.TimeDistributed(keras.layers.Dense(vocab_size_label, activation="softmax")))
model.compile(optimizer=optim,loss='sparse_categorical_crossentropy',metrics=["accuracy"])
model.summary()
Run Code Online (Sandbox Code Playgroud)

我已经为 NER Tagging 构建了一个 Bi-lstm 模型,现在我想在其中引入 CRF 层。我很困惑如何使用 Tensorflow 插入 CRF 层

tfa.text.crf_log_likelihood(
    inputs,
    tag_indices,
    sequence_lengths,
    transition_params=None
)
Run Code Online (Sandbox Code Playgroud)

我在 tfa.txt 中找到了这个,并且有 3 个关于这个函数的查询: 1. 我如何传递这些参数?2. 我是否必须在编译器中将此输出用作损失(log_likelihood 的负数)。有人可以帮助我吗?

python crf deep-learning tensorflow ner

9
推荐指数
1
解决办法
1468
查看次数

使用Python解析PDF教科书中的索引页面

我必须将PDF页面中的文本从缩进中提取到CSV文件中.

PDF教科书的索引页面:

我应该将文本拆分为类和子类型层次结构以及页码.例如,在图像中, Application server是类,Apache Tomcat是页码275中的子类

这是CSV的预期输出:

我使用Tika解析器来解析PDF,但是在解析的内容中没有正确维护缩进(不是唯一的),以便将文本拆分为类和子类.

这是解析文本的样子:

任何人都可以建议我这个要求的正确方法吗?

python pdftotext pdfminer ner natural-language-processing

8
推荐指数
1
解决办法
865
查看次数

有没有办法用spaCy的NER来计算每个实体类型的指标?

有没有办法在spaCy的NER模型中提取每个实体类型的指标(精确度,召回率,f1得分)?

看起来像这样的东西:

         precision    recall  f1-score   support

  B-LOC      0.810     0.784     0.797      1084
  I-LOC      0.690     0.637     0.662       325
 B-MISC      0.731     0.569     0.640       339
 I-MISC      0.699     0.589     0.639       557
  B-ORG      0.807     0.832     0.820      1400
  I-ORG      0.852     0.786     0.818      1104
  B-PER      0.850     0.884     0.867       735
  I-PER      0.893     0.943     0.917       634
Run Code Online (Sandbox Code Playgroud)

平均/总计0.809 0.787 0.796 6178

取自:http://www.davidsbatista.net/blog/2018/05/09/Named_Entity_Evaluation/

谢谢!

python metrics entity spacy ner

8
推荐指数
3
解决办法
1160
查看次数

了解Spacy的得分手输出

我正在评估我使用Spacy构建的自定义NER模型.我正在使用Spacy的Scorer课程评估训练集.

    def Eval(examples):
    # test the saved model
    print("Loading from", './model6/')
    ner_model = spacy.load('./model6/')

    scorer = Scorer()
    try:
        for input_, annot in examples:
            doc_gold_text = ner_model.make_doc(input_)
            gold = GoldParse(doc_gold_text, entities=annot['entities'])
            pred_value = ner_model(input_)
            scorer.score(pred_value, gold)
    except Exception as e: print(e)

    print(scorer.scores)
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我不明白输出.这是我为每个训练集获得的内容.

{'uas': 0.0, 'las': 0.0, 'ents_p': 90.14084507042254, 'ents_r': 92.7536231884058, 'ents_f': 91.42857142857143, 'tags_acc': 0.0, 'token_acc': 100.0}

{'uas': 0.0, 'las': 0.0, 'ents_p': 91.12227805695142, 'ents_r': 93.47079037800687, 'ents_f': 92.28159457167091, 'tags_acc': 0.0, 'token_acc': 100.0}

{'uas': 0.0, 'las': 0.0, 'ents_p': 92.45614035087719, 'ents_r': 92.9453262786596, 'ents_f': 92.70008795074759, …
Run Code Online (Sandbox Code Playgroud)

python spacy ner

7
推荐指数
1
解决办法
1195
查看次数

检测 spacy 中的日期

有没有办法编写一个基于规则的系统来从合同文本中捕获诸如开始/结束日期之类的内容。这里有几个真实的例子。我正在加粗我希望 spacy 自动检测的日期实体。如果您有与 spacy 不同的其他想法也可以!

  1. 本租约的初始期限为五 (5) 年,自 February 1, 2012、(“租赁开始日期”)起至January 31, 2017 (“初始租赁期限”)届满。

  2. 期限:一 (1) 年开始January 1, 2007(“开始日期”)和结束 December 31, 2007(“到期日期”)。

  3. 本租赁协议签订期限为 15 年,自 年 月 日January 1, 2014起至 年末December 31, 2028

python nlp spacy ner

7
推荐指数
2
解决办法
6756
查看次数

Spacy 3 命名实体识别的置信度评分

我需要获得 NER 'de_core_news_lg' 模型预测的标签的置信度分数。在 Spacy 2 中有一个众所周知的解决方案:

nlp = spacy.load('de_core_news_lg')
doc = nlp('ich möchte mit frau Mustermann in der Musterbank sprechen')
text = content
doc = nlp.make_doc(text)
beams = nlp.entity.beam_parse([doc], beam_width=16, beam_density=0.0001)
for score, ents in nlp.entity.moves.get_beam_parses(beams[0]):
    print (score, ents)
    entity_scores = defaultdict(float)
    for start, end, label in ents:
        # print ("here")
        entity_scores[(start, end, label)] += score
        print ('entity_scores', entity_scores)
Run Code Online (Sandbox Code Playgroud)

但是,在 Spacy 3 中,我收到以下错误:

AttributeError: 'German' object has no attribute 'entity'
Run Code Online (Sandbox Code Playgroud)

显然language对象不再具有entity属性。有谁知道如何在 Spacy 3 中获得置信度分数?

python nlp ner spacy-3

6
推荐指数
1
解决办法
624
查看次数

如何使 spaCy 不区分大小写

查找实体名称时如何使 spaCy 不区分大小写?

有没有我应该添加的代码片段或其他内容,因为这些问题可能会提到不是大写的实体?

def analyseQuestion(question):

    doc = nlp(question)
    entity=doc.ents 

    return entity

print(analyseQuestion("what is the best seller of Nicholas Sparks "))  
print(analyseQuestion("what is the best seller of nicholas sparks "))    
Run Code Online (Sandbox Code Playgroud)

这使

(Nicholas Sparks,)  
()
Run Code Online (Sandbox Code Playgroud)

case-sensitive spacy ner

5
推荐指数
1
解决办法
6426
查看次数

当我们训练自定义模型时,Spacy 使用哪种深度学习算法?

当我们训练自定义模型时,我确实看到我们有 dropout 和 n_iter 参数需要调整,但是 Spacy 使用哪种深度学习算法来训练自定义模型?另外,当添加新的实体类型时,创建空白还是在现有模型上训练它好?

nlp spacy ner

5
推荐指数
1
解决办法
2879
查看次数