获取 johnsnowlabs 企业级 NLP 库生态系统 超过 21,000 个企业级 NLP 模型,支持 200 多种语言,采用开源 johnsnowlabs library. 查看所有 24,000+ 个模型,请访问 John Snow Labs 模型中心
安装和设置
pip install johnsnowlabs
uv add johnsnowlabs
To [install enterprise features](https://nlp.johnsnowlabs.com/docs/en/jsl/install_已授权_快速运行:
# for more details see https://nlp.johnsnowlabs.com/docs/en/jsl/install_licensed_quick
nlp.install()
您可以使用以下方式嵌入您的查询和文档 gpu,cpu,apple_silicon,aarch 优化的二进制文件。 默认使用 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)
## Embed Document with AARCH:
python
documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','aarch')
output = embedding.embed_documents(documents)
模型使用以下方式加载 nlp.load Spark 会话使用以下方式启动 nlp.start() 在底层运行。