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()
您可以使用 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)
使用 AARCH 嵌入文件:
```python
documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','aarch')
output = embedding.embed_documents(documents)
模型透過 nlp.load 載入,而 spark 工作階段則在底層透過 nlp.start() 啟動。