如何在Julia中导入NLP模型(facebook bart Large mnli模型)?
我想寻求帮助在 Julia 中导入 zero-shot-classification
的 bart-large-mnli
模型?
模型参考:https://metatext.io/models/facebook-bart-large -mnli
这是我想要移植到 Julia 的 python 示例:
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="facebook/bart-large-mnli")
sequence_to_classify = "one day I will see the world"
candidate_labels = ['travel', 'cooking', 'dancing']
classifier(sequence_to_classify, candidate_labels)
预期输出:
{'sequence': 'one day I will see the world',
'labels': ['travel', 'dancing', 'cooking'],
'scores': [0.9938650727272034, 0.0032738070003688335, 0.002861041808500886]
}
请建议或建议针对此场景的解决方案。 期待大家的回应。谢谢!
I would like to seek help in importing the bart-large-mnli
model for zero-shot-classification
in Julia?
Reference to the model: https://metatext.io/models/facebook-bart-large-mnli
This is the python example which I want to port to Julia:
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="facebook/bart-large-mnli")
sequence_to_classify = "one day I will see the world"
candidate_labels = ['travel', 'cooking', 'dancing']
classifier(sequence_to_classify, candidate_labels)
Expected Output:
{'sequence': 'one day I will see the world',
'labels': ['travel', 'dancing', 'cooking'],
'scores': [0.9938650727272034, 0.0032738070003688335, 0.002861041808500886]
}
Please advise or suggest a solution for this scenario.
Look forward to the responses. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定您想要的用例是什么,但如果您只想访问 Julia 代码中预训练的 Huggingface 模型输出,您可以使用 PyCall.jl 调用该 Python 代码并返回您感兴趣的字典。
也就是说,在 Julia 中,运行 py"""..."" 中的 python 代码“
那么Python 全局变量
output
可以通过 Julia 中的py"output"
访问(Pythondict
自动转换为 JuliaDict),就像
您也可以通过在字符串后面放置
o
来将其作为 PyObject 获取,而无需自动类型转换:您还可以通过导入 python 包
transformers
来获得类似的东西code> 使用 PyCall 进入 Juliapyimport()
,现在 Julia 对象
output
将是您想要的 Dict。Not sure quite what your desired use case is, but if you want to just have access to the pretrained huggingface model output in your Julia code, you can use PyCall.jl to call that Python code and return the dictionary you're interested in.
That is, in Julia, run the python code in py"""..."""
then the Python global variable
output
will be accessible withpy"output"
in Julia (the Pythondict
automatically converted to a JuliaDict
), likeyou can also get it as a PyObject without the automatic type conversion, by putting
o
after the string:You could also get something similar by importing the python package
transformers
into Julia with PyCall'spyimport()
, andnow the Julia object
output
will be the Dict you want.