SSブログ

月下美人とホタル [相鉄沿線]

毎年6月頃に咲く月下美人、今年は5月24日の朝には、咲いていました。


いつも月下美人が咲く頃には、ホタルが飛び始めるので、金曜日の夜、こども自然公園に行ってみたら、数頭のホタルが飛んでいました。


今年も、昨年のように沢山のホタルが見られるといいな。
nice!(12)  コメント(1) 

ひさしぶりにカワセミに会いました [相鉄沿線]

こども自然公園の中池で、ひさしぶりにカワセミに会いました。




桑の実
今年はもう熟しています。


ビワの実も



近くの空き地では、特定外来生物のオオキンケイギクが大繁殖

繁殖力がとても強くて、在来種を駆逐してしまうので、日本では栽培が禁止されているそうですが、アメリカでは、フロリダ州の花になっています。(日本語のWikipediaには、フロリダ州の花は、ハルシャギクって書いてありますが、英語版 https://en.wikipedia.org/wiki/List_of_U.S._state_and_territory_flowers と写真も違いますね。)
nice!(10)  コメント(0) 

逗子海岸 [湘南・鎌倉]

今週末は、土日とも天気が悪くて出かけなかったので、ゴールデンウィークに行った逗子海岸の写真です。




江ノ島や鎌倉と違って、商業施設が少ないので、ひとでが少なかったです。








nice!(14)  コメント(0) 

横浜のバラ [ヨコハマ]

イングリッシュローズの庭
IMG_0523.jpg

IMG_0527.jpg

P1140209.jpg

ベーリック・ホール
P1140196.jpg


山手234番館
P1140197.jpg

P1140199.jpg


ホテルニューグランド
IMG_0544.jpg

山下公園
IMG_0537.jpg




最近話題のChatGPTなどのLLM (Large Language Models)の分野では、モデルの他に、LLMを利用してドキュメントの検索を行ったりチャットボットを作るための仕組みを提供するLangChainやLlamaIndexなどが公開されています。

LangChainが、普通のパソコン (大容量メモリやGPUが不要)でも動かせるGPT4ALLやLlama-cppをサポートした(参照: https://python.langchain.com/en/latest/modules/models/llms/integrations.html )ので、メモリ16GBのノートパソコンで、LLukas22/alpaca-native-7B-4bit-ggjt ( https://huggingface.co/LLukas22/alpaca-native-7B-4bit-ggjt )という4.2GBのサイズのモデルと組み合わせて動かしてみました。


# モデルのダウンロード
from huggingface_hub import hf_hub_download

Llama-cpp_MODEL_PATH = "ggjt-model.bin"
# Download the model.
hf_hub_download(repo_id="LLukas22/alpaca-native-7B-4bit-ggjt", 
  filename=Llama-cpp_MODEL_PATH, local_dir=".")

from langchain.llms import LlamaCpp
from langchain import PromptTemplate, LLMChain

# QA用のテンプレートを作る
template = """
Question: {question}
Answer: Let's think step by step.
"""

prompt = PromptTemplate(template=template, 
  input_variables=["question"])
llm = LlamaCpp(model_path=Llama-cpp_MODEL_PATH)

# NSGA上瀬谷基地について聞いてみます。
question = "What is the NSGA Kami seya base ?"

llm_chain.run(question)

"1. First, we need to know what 'NSGA' stands for. It stands for Non-Standard Generalized Array. \n2. Next, we need to know what a 'Kami seya' is. A Kami seya is an ancient Japanese castle tower, usually made of wood and built on the top of a mountain or hill. \n3. Finally, we need to understand how NSGA Kami Seya Base is related to these two things. NSGA Kami Seya Base is an open-source project that provides a general-purpose library for manipulating 2D geometric shapes using linear algebra, which can be used to build 3D computer graphics and animation. This library implements optimized geometry algorithms, such as the ones used in Kami Seya, a traditional Japanese castle tower. These algorithms help reduce computational time and memory usage, allowing users to create complex 3D scenes with minimal resources."

"NSGA Kami Seya Base is an open-source project."とか、予想通り、よくわからない答えが返ってきました。

上瀬谷基地についての情報を得るために、
Navy Information Operations Command (NIOC) Yokosuka, Japanのサイト
https://www.navifor.usff.navy.mil/Organization/Operational-Support/NIOC-Hawaii/NIOC-Hawaii-N3J-Department/About-Us/History/

Naval Computer and Telecommunications Station (NCTS) Yokosuka, Japanのサイト
https://www.navifor.usff.navy.mil/Organization/Operational-Support/NCTS-Far-East-Yokosuka/About-Us/History/
を読み込ませてから、同じ質問をしてみます。

こんな仕組み
LangCain_QA.jpg

from langchain.embeddings import LlamaCppEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import FAISS
from langchain.document_loaders import TextLoader

# Embeddingsの作成、LlamaCppEmbeddings関数は、CPUを利用する場合
# n_threadsでスレッド数を指定できる。
embeddings = LlamaCppEmbeddings(model_path=Llama-cpp_MODEL_PATH,
  n_ctx= 2048, n_threads = 8)

from langchain.document_loaders import TextLoader

# 上瀬谷基地に関するテキストの読み込み
loader = TextLoader('data/kamiseya.txt')
documents = loader.load()
text_splitter = RecursiveCharacterTextSplitter(
    chunk_size = 1000, 
    chunk_overlap = 50,
    length_function = len)
docs = text_splitter.split_documents(documents)

# テキストをFAISSで扱えるベクトルデータにする
db = FAISS.from_documents(docs, embeddings)
db.save_local("faiss_index")

# Use llama-cpp as the LLM for langchain
callback_manager
    = CallbackManager([StreamingStdOutCallbackHandler()])

llm = LlamaCpp(
    model_path=Llama-cpp_MODEL_PATH,
    n_ctx= 2048,
    callback_manager=callback_manager, 
    verbose=True,
    use_mlock=True
)

# 質問文とドキュメントのデータでQAができるようにする。
retriever = db.as_retriever()
qa = RetrievalQA.from_chain_type(llm=llm,
    chain_type="stuff", retriever=retriever)

response = qa.run(query)

print(response)

The National Security Agency's Kami Seya (NSA-K) was a U.S. Navy facility located in Yokosuka, Japan which provided communication services to various naval units and agencies until it was disestablished in October 2014. It is known for being one of the first two National Security Agency (NSA) sites, the other being Fort Meade, Maryland. It was used during World War II as a Fleet Radio Unit, tracking enemy vessels and providing radio communications for U.S. naval forces in the Pacific Ocean area. The National Security Agency's Kami Seya (NSA-K) was a U.S. Navy facility located in Yokosuka, Japan which provided communication services to various naval units and agencies until it was disestablished in October 2014. It is known for being one of the first two National Security Agency (NSA) sites, the other being Fort Meade, Maryland. It was used during World War II as a Fleet Radio Unit, tracking enemy vessels and providing radio communications for U.S. naval forces in the Pacific Ocean area.

上瀬谷基地は、横須賀にあるとか、ちょっと間違っているところもありますが、かなり良い答えが返ってきました。

P1140315.jpg

ChatGPTなどのLLMは、言語モデルだけでなく、言語モデルとテキストやPDF、Microsoft Word、Pandas DataFrame、Slackなどさまざまなデータソースと接続させたり、ユーザーの要求を「どのような手段を使ってどういう順番で解決するか」を 自動的に決定してくれるエージェントと呼ばれる機能と組み合わせる仕組みなどのエコシステムができていて、この分野の進化はまだまだ続きそうですね。


nice!(14)  コメント(0)