Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
OurBuilding Ambient Agents with LangGraph course is now available on LangChain Academy!
Open In ColabOpen on GitHub

John Snow Labs

John Snow Labs NLP & LLM ecosystem includes software libraries for state-of-the-art AI at scale, Responsible AI, No-Code AI, and access to over 20,000 models for Healthcare, Legal, Finance, etc.

Models are loaded withnlp.load and spark session is started >withnlp.start() under the hood.For all 24.000+ models, see theJohn Snow Labs Model Models Hub

Setting up

%pip install--upgrade--quiet  johnsnowlabs
# If you have a enterprise license, you can run this to install enterprise features
# from johnsnowlabs import nlp
# nlp.install()

Example

from langchain_community.embeddings.johnsnowlabsimport JohnSnowLabsEmbeddings

Initialize Johnsnowlabs Embeddings and Spark Session

embedder= JohnSnowLabsEmbeddings("en.embed_sentence.biobert.clinical_base_cased")

Define some example texts . These could be any documents that you want to analyze - for example, news articles, social media posts, or product reviews.

texts=["Cancer is caused by smoking","Antibiotics aren't painkiller"]

Generate and print embeddings for the texts . The JohnSnowLabsEmbeddings class generates an embedding for each document, which is a numerical representation of the document's content. These embeddings can be used for various natural language processing tasks, such as document similarity comparison or text classification.

embeddings= embedder.embed_documents(texts)
for i, embeddinginenumerate(embeddings):
print(f"Embedding for document{i+1}:{embedding}")

Generate and print an embedding for a single piece of text. You can also generate an embedding for a single piece of text, such as a search query. This can be useful for tasks like information retrieval, where you want to find documents that are similar to a given query.

query="Cancer is caused by smoking"
query_embedding= embedder.embed_query(query)
print(f"Embedding for query:{query_embedding}")

Related


[8]ページ先頭

©2009-2025 Movatter.jp