NLP Cloud
NLP Cloud 為 NER、情感分析、分類、摘要、意譯、文法和拼字校正、關鍵字和關鍵詞組擷取、聊天機器人、產品描述和廣告生成、意圖分類、文字生成、圖像生成、部落格文章生成、程式碼生成、問答、自動語音辨識、機器翻譯、語言偵測、語意搜尋、語意相似度、Tokenization、POS 標記和依賴性剖析提供高效能的預先訓練或自訂模型。它已準備好投入生產,並透過 REST API 提供服務。
此範例說明如何使用 LangChain 與 NLP Cloud
模型互動。
%pip install --upgrade --quiet nlpcloud
# get a token: https://docs.nlpcloud.com/#authentication
from getpass import getpass
NLPCLOUD_API_KEY = getpass()
········
import os
os.environ["NLPCLOUD_API_KEY"] = NLPCLOUD_API_KEY
from langchain.chains import LLMChain
from langchain_community.llms import NLPCloud
from langchain_core.prompts import PromptTemplate
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate.from_template(template)
llm = NLPCloud()
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
llm_chain.run(question)
' Justin Bieber was born in 1994, so the team that won the Super Bowl that year was the San Francisco 49ers.'