Johnsnowlabs
访问 johnsnowlabs 企业 NLP 库生态系统,拥有超过 21,000 个企业 NLP 模型,涵盖 200 多种语言,使用开源的 johnsnowlabs
库。有关 24,000+ 模型的详细信息,请参见 John Snow Labs Model Models Hub
安装与设置
pip install johnsnowlabs
要 安装企业功能,请运行:
# 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)
使用苹果硅(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()在后台启动。