我有一个功能设置与Tensorflow和Jupyter。我已经配置了Tensorflow==1.14在gpu上运行。
现在说说问题:我使用的是一个名为DeepPavlov的开源对话式AI框架。它的一切都在运行(在配置方面),但我没有多少从笔记本上调用python的经验(或者根本没有)。我可以在控制台运行这段代码,但这不是我的目标。我的问题是
我有一段普通的python代码
from deeppavlov import build_model, configs
model = build_model(configs.squad.squad, download=True)
model(['DeepPavlov is library for NLP and dialog systems.'], ['What is DeepPavlov?'])
这是我的输出
2020-04-20 07:08:23.478 INFO in 'deeppavlov.download'['download'] at line 117: Skipped http://files.deeppavlov.ai/deeppavlov_data/squad_model_1.4_cpu_compatible.tar.gz download because of matching hashes
2020-04-20 07:08:37.884 INFO in 'deeppavlov.download'['download'] at line 117: Skipped http://files.deeppavlov.ai/embeddings/wiki-news-300d-1M.vec download because of matching hashes
2020-04-20 07:08:38.343 INFO in 'deeppavlov.download'['download'] at line 117: Skipped http://files.deeppavlov.ai/embeddings/wiki-news-300d-1M-char.vec download because of matching hashes
2020-04-20 07:08:38.364 INFO in 'deeppavlov.models.preprocessors.squad_preprocessor'['squad_preprocessor'] at line 310: SquadVocabEmbedder: loading saved tokens vocab from C:\Users\Administrator\.deeppavlov\models\squad_model\emb\vocab_embedder.pckl
2020-04-20 07:08:39.158 INFO in 'deeppavlov.models.preprocessors.squad_preprocessor'['squad_preprocessor'] at line 310: SquadVocabEmbedder: loading saved chars vocab from C:\Users\Administrator\.deeppavlov\models\squad_model\emb\char_vocab_embedder.pckl
2020-04-20 07:08:40.599 INFO in 'deeppavlov.core.layers.tf_layers'['tf_layers'] at line 615:
Warning! tf.contrib.cudnn_rnn.CudnnCompatibleGRUCell is used. It is okay for inference mode, but if you train your model with this cell it could NOT be used with tf.contrib.cudnn_rnn.CudnnGRUCell later.
2020-04-20 07:08:41.185 INFO in 'deeppavlov.core.layers.tf_layers'['tf_layers'] at line 615:
Warning! tf.contrib.cudnn_rnn.CudnnCompatibleGRUCell is used. It is okay for inference mode, but if you train your model with this cell it could NOT be used with tf.contrib.cudnn_rnn.CudnnGRUCell later.
2020-04-20 07:08:41.520 INFO in 'deeppavlov.core.layers.tf_layers'['tf_layers'] at line 615:
Warning! tf.contrib.cudnn_rnn.CudnnCompatibleGRUCell is used. It is okay for inference mode, but if you train your model with this cell it could NOT be used with tf.contrib.cudnn_rnn.CudnnGRUCell later.
2020-04-20 07:08:41.748 INFO in 'deeppavlov.core.layers.tf_layers'['tf_layers'] at line 615:
Warning! tf.contrib.cudnn_rnn.CudnnCompatibleGRUCell is used. It is okay for inference mode, but if you train your model with this cell it could NOT be used with tf.contrib.cudnn_rnn.CudnnGRUCell later.
2020-04-20 07:09:23.205 INFO in 'deeppavlov.core.models.tf_model'['tf_model'] at line 51: [loading model from C:\Users\Administrator\.deeppavlov\models\squad_model\model]
INFO:tensorflow:Restoring parameters from C:\Users\Administrator\.deeppavlov\models\squad_model\model
[['library for NLP and dialog systems'], [14], [8040850.5]]
它正常运行,但没有给我任何交互选项,比如提示或其他东西,它只是停止。
我的目标是得到一个提示,在那里我可以输入并得到一个输出(文本等)。我知道我可能在python notebookcell的使用上犯了一些非常基本的错误,如果你需要更多的信息,请问。 谢谢。
DeepPavlov自带了一堆由TensorFlow和Keras驱动的预定义组件,用于解决NLP相关问题。
你正在使用的是问题解答的BERT。 上下文问题解答是指在给定的上下文(比如维基百科的一段文字)上找到问题的答案,每个问题的答案都是上下文的一个片段。
该模型在调用时返回如下 model(contexts_list, questions_list)
answers_list, answers_starts_list, logits_list
例1:
from deeppavlov import build_model, configs
model = build_model(configs.squad.squad_bert)
model(['DeepPavlov is library for NLP and dialog systems.'], ['What is DeepPavlov?'])
輸出
INFO:tensorflow:Restoring parameters from C:\Users\RF00538236\.deeppavlov\models\squad_bert\model
[['library for NLP and dialog systems'], [14], [158.80197143554688]]
答案返回答案列表、答案起始列表(答案在第14个字符处)和logits列表。
例2 : 复制了关于圣雄甘地的上下文,来自于 此处.
model(['Born and raised in a Hindu family in coastal Gujarat, western India, Gandhi was trained in law at the Inner Temple, London, and called to the bar at age 22 in June 1891. After two uncertain years in India, where he was unable to start a successful law practice, he moved to South Africa in 1893 to represent an Indian merchant in a lawsuit. He went on to stay for 21 years. It was in South Africa that Gandhi raised a family, and first employed nonviolent resistance in a campaign for civil rights.'],['What was Gandhi trained at?'])
产出 -
[['law'], [91], [106616.5390625]]
或者,您可以构建 deeppavlov 与模型交互。 您可以通过命令行运行它与模型交互,并使用交互参数和模型的配置文件名(-d表示下载所有需要的文件)。或者您可以使用下面例子中的 Python Jupyter 代码中的 build_model。
安装dependecies -
!python -m deeppavlov install tfidf_logreg_en_faq
例1--------------。
from deeppavlov import configs
from deeppavlov.core.common.file import read_json
from deeppavlov.core.commands.infer import build_model
faq = build_model(configs.faq.tfidf_logreg_en_faq, download = True)
a = faq(["I need help"])
a
产出 -
[['If you have any further inquiries, you can address them to the International Students Office, which is located in the Auditorium Building, Room 315. The phone number is (7-495) 408-7043.'],
[[0.0005971888349561158,
0.0004990413077070781,
0.0003260898111600398,
0.0004955716039888539,
0.9920733828654503,
0.0004564850775432216,
0.0012178910790545932,
0.0006631341572001673,
0.0006362137679856412,
0.0010445215260383672,
0.0011939766282353169,
0.0004438081627736979,
0.00035269517790671484]]]
例2--------------。
a = faq(["i need help on medical offices"])
a
产出 -
[['All Russian universities have medical offices for first aid and general medical care.'],
[[0.00030839735143966185,
0.0005853193249863691,
0.0004579660993813656,
0.0004773336684218436,
0.4791163218068051,
0.00028413386610718364,
0.0009917714916957442,
0.00047599362403134946,
0.000766086074333974,
0.0007509714241461073,
0.5120912464072629,
0.0032745806081316926,
0.0004198782532568704]]]
希望能回答你的问题。祝您学习愉快。