Skip to main content
Open on GitHub

Johnsnowlabs

通过开源的 johnsnowlabs 库,访问包含超过 21,000 个企业级 NLP 模型、支持 200 多种语言的 johnsnowlabs 企业级 NLP 库生态系统。 查看全部 24,000+ 个模型,请访问 John Snow Labs 模型中心

安装与设置

pip install johnsnowlabs

要[安装企业功能](https://nlp.johnsnowlabs.com/docs/zh/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() 启动。