我正在尝试评估使用spacy lib创建的训练有素的NER模型.通常对于这些问题,您可以使用f1分数(精确度和召回率之间的比率).我在文档中找不到训练有素的NER模型的精确度函数.
我不确定它是否正确,但我尝试使用以下方式(示例)并使用f1_scorefrom sklearn:
from sklearn.metrics import f1_score
import spacy
from spacy.gold import GoldParse
nlp = spacy.load("en") #load NER model
test_text = "my name is John" # text to test accuracy
doc_to_test = nlp(test_text) # transform the text to spacy doc format
# we create a golden doc where we know the tagged entity for the text to be tested
doc_gold_text= nlp.make_doc(test_text)
entity_offsets_of_gold_text = [(11, 15,"PERSON")]
gold = GoldParse(doc_gold_text, entities=entity_offsets_of_gold_text)
# bring the data in …Run Code Online (Sandbox Code Playgroud) 在发布消息之前,代码会在进行实际发布之前检查 RabbitMQ 连接是否未关闭(请参阅下面的调用代码)。然而,当这个检查完成时,似乎出现了一些奇怪的 TypeError。
更多细节:
pika.SelectConnection)侦听特定队列。pika.BlockingConnection)将其他消息发布到另一个队列。rmq_consumer_connection.ioloop.start()是一个阻塞操作(因此不能做等效的rmq_producer_connection.ioloop.start())。我可能会考虑在未来进行优化(例如,为消费者和生产者使用单独的线程,这样两者都可以是异步的)。堆栈跟踪如下:
Apr 05 19:25:16 prod python[23326]: job|callback_user_queue|ERROR| Exception in callback_user_queue(..)
Apr 05 19:25:16 prod python[23326]: Traceback (most recent call last):
Apr 05 19:25:16 prod python[23326]: File "/opt/app/gateway_messenger.py", line 282, in send_to_gateway
Apr 05 19:25:16 prod python[23326]: gv.rmq_producer_connection.process_data_events()
Apr 05 19:25:16 prod python[23326]: File "/home/prod/anaconda3/envs/venv/lib/python3.5/site-packages/pika/adapters/blocking_connection.py", line 751, in process_data_events
Apr 05 19:25:16 prod python[23326]: with _IoloopTimerContext(time_limit, self._impl) as timer:
Apr …Run Code Online (Sandbox Code Playgroud)