Skip to main content
Open on GitHub

Johnsnowlabs

访问johnsnowlabs的企业NLP库生态系统,通过开源的johnsnowlabs库,拥有超过21,000个企业NLP模型,涵盖200多种语言。要查看所有24,000多个模型,请访问John Snow Labs模型中心

安装与设置

pip install johnsnowlabs

要[安装企业功能](https://nlp.johnsnowlabs.com/docs/en/jsl/install_licensed_quick,请运行:

# for more details see https://nlp.johnsnowlabs.com/docs/en/jsl/install_licensed_quick
nlp.install()

您可以使用基于gpucpuapple_siliconaarch优化的二进制文件嵌入您的查询和文档。 默认情况下使用cpu二进制文件。 一旦会话开始,您必须重新启动您的笔记本以在GPU或CPU之间切换,否则更改将不会生效。

嵌入查询与CPU:

document = "foo bar"
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert')
output = embedding.embed_query(document)

使用GPU嵌入查询:

document = "foo bar"
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','gpu')
output = embedding.embed_query(document)

在Apple Silicon(M1、M2等)上嵌入查询:

documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','apple_silicon')
output = embedding.embed_query(document)

使用AARCH嵌入查询:

documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','aarch')
output = embedding.embed_query(document)

使用CPU嵌入文档:

documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','gpu')
output = embedding.embed_documents(documents)

使用GPU嵌入文档:

documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','gpu')
output = embedding.embed_documents(documents)

嵌入文档与Apple Silicon (M1, M2, 等..):


```python
documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','apple_silicon')
output = embedding.embed_documents(documents)

使用AARCH嵌入文档:


```python
documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','aarch')
output = embedding.embed_documents(documents)

模型通过nlp.load加载,并且Spark会话在后台通过nlp.start()启动。


这个页面有帮助吗?