跳至主要内容

Johnsnowlabs

通过开源 johnsnowlabs 库,访问 johnsnowlabs 企业 NLP 库生态系统,其中包含 200 多种语言的 21,000 多个企业 NLP 模型。有关所有 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,etc..) 嵌入查询:

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,etc..) 嵌入文档:


```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() 启动。


此页是否对您有帮助?