Views
No views yet
tokyotech-llm/Llama-3.1-Swallow-8B-Instruct-v0.1 model.
The fine-tuning was performed using a RAG (Retrieval Augmented Generation) approach, leveraging information retrieved from the "Reinforcement Learning An Introduction Second edition" by Richard S. Sutton and Andrew G. Barto PDF document to answer questions based on a Japanese instruction dataset (ichikara-instruction-003-001-1.json).tokyotech-llm/Llama-3.1-Swallow-8B-Instruct-v0.1 model's ability to answer questions by utilizing context retrieved from the "Reinforcement Learning An Introduction Second edition" book. It was fine-tuned using QLoRA on a dataset where questions were paired with relevant context from the book and expected answers from the ichikara-instruction dataset.tokyotech-llm/Llama-3.1-Swallow-8B-Instruct-v0.1, which is Llama 3 Community License). Please refer to the base model's license.tokyotech-llm/Llama-3.1-Swallow-8B-Instruct-v0.1https://huggingface.co/yf591/llama3-8b-rag-sft-lora-v1https://huggingface.co/tokyotech-llm/Llama-3.1-Swallow-8B-Instruct-v0.1ichikara-instruction-003-001-1.jsontokyotech-llm/Llama-3.1-Swallow-8B-Instruct-v0.1 base model..
It can then be used for question answering tasks where the questions are related to the content of "Reinforcement Learning An Introduction Second edition" or similar technical documents, utilizing a RAG pipeline.1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig # BitsAndBytesConfigをインポート
2from peft import PeftModel
3
4base_model_id = "tokyotech-llm/Llama-3.1-Swallow-8B-Instruct-v0.1"
5adapter_id = "yf591/llama3-8b-rag-sft-lora-v1"
6
7# Optional: Configure quantization for loading the base model
8# bnb_config = BitsAndBytesConfig(
9# load_in_4bit=True,
10# bnb_4bit_quant_type="nf4",
11# bnb_4bit_compute_dtype="float16", # Or torch.bfloat16 if available and preferred
12# bnb_4bit_use_double_quant=True,
13# )
14
15# Load the base model
16base_model = AutoModelForCausalLM.from_pretrained(
17 base_model_id,
18 # quantization_config=bnb_config, # Quantization settings if needed
19 device_map="auto",
20 trust_remote_code=True
21)
22
23# Load the tokenizer
24tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
25if tokenizer.pad_token is None:
26 tokenizer.pad_token = tokenizer.eos_token
27
28# Load the LoRA adapter
29model = PeftModel.from_pretrained(base_model, adapter_id)
30# For potentially faster inference (at the cost of higher memory during merging):
31# model = model.merge_and_unload() # Note: this requires sufficient memory and modifies the model in place
32
33# Example RAG prompt structure
34question = "Please explain Markov Decision Processes, policies, state-value functions, and action-value functions in reinforcement learning."
35# In a real RAG setup, 'context' would be retrieved from Richard S. Sutton and Andrew G. Barto's book.
36context = """
37A Markov Decision Process (MDP) formally describes an environment for reinforcement learning.
38Key components include states (S), actions (A), a transition probability function P(s'|s,a),
39and a reward function R(s,a,s'). A policy (π) is a mapping from states to probabilities
40of selecting each possible action. The state-value function Vπ(s) is the expected return
41starting from state s and following policy π. The action-value function Qπ(s,a) is the
42expected return starting from state s, taking action a, and then following policy π.
43... (text retrieved from "Reinforcement Learning: An Introduction" by Sutton & Barto) ...
44"""
45
46prompt = f"""### 指示:
47以下のコンテキスト情報を使用して、質問に対する回答を生成してください。
48コンテキスト情報に含まれる事実のみを使用し、含まれていない情報は推測しないでください。
49
50### コンテキスト:
51{context}
52
53### 質問:
54{question}
55
56### 回答:
57"""
58
59inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
60# Generate text
61# Note: For instruct models, generation parameters like temperature, top_p, etc.,
62# might be already well-tuned in their default generation_config.
63# Adjust max_new_tokens as needed for desired response length.
64outputs = model.generate(**inputs, max_new_tokens=300, temperature=0.7, top_p=0.9, do_sample=True)
65response_full = tokenizer.decode(outputs[0], skip_special_tokens=True)
66
67# Extract only the answer part
68answer_part = response_full.split("### 回答:")[-1].strip()
69print(answer_part)ichikara-instruction) might have its own biases which could be reflected in the model's responses.Llama-3.1-Swallow-8B-Instruct-v0.1) has its own inherent biases, risks, and limitations. Please refer to its model card.ichikara-instruction-003-001-1.json (a Japanese instruction-following dataset).ichikara-instruction dataset based on the instruction text.ichikara-instruction dataset.intfloat/multilingual-e5-large.tokyotech-llm/Llama-3.1-Swallow-8B-Instruct-v0.1 with a max_length of 2048 (or 512 if you changed it).r: 8alpha: 16dropout: 0.05q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_projDEFAULT_LEARNING_RATE)DEFAULT_PER_DEVICE_BATCH_SIZE)DEFAULT_GRADIENT_ACCUMULATION_STEPS)max_epochs or DEFAULT_NUM_TRAIN_EPOCHS used for the final training)DEFAULT_LR_SCHEDULER_TYPE)DEFAULT_WARMUP_RATIO)nf4, float16 compute dtype, double quant)max_length=512).### 質問:
強化学習におけるマルコフ決定過程、方策、状態価値関数、行動価値関数について教えてください。
### 回答:
強化学習では学習対象となるエージェントが環境との相互作用によって動的に変化する状況下で意思決定を行うことを目指します。このような意思決定には必ず「評価」というものが必要です。その評価に使われる重要な概念が、マルコフ決定過程(Markov Decision Process)、方策(Policy)、状態価値関数(State Value Function)、行動価値関数(Action-Value Function)といったものです。これらの概念はどれも強化学習において非常に重要であり、これらを理解していることでより深い学びにつながります。
まず始めから一つづつ説明していきましょう。
* マルコフ決定過程:この問題設定は次のように記述できます。ある時間ステップ t において環境が現在持っている状態 S t を考える。そしてエージェントはそのとき取ることのできる行動 A t の集合の中から一つの行動を選択する。すると確率分布 P(A t |S t ) が従ってA t が発生し、そして遷移先の状態と報酬が決まるというように考えていく。各状態における各行動を起こした場合にどのようなことが起きたかなどを予想せよというのがMDPのタスクである。
* 状態価値関数:ある状態からの期待される結果として何が得られるのか、それが最大になるのはいつなのかということが大切になります。それを表すものとして「状態価値関数」がありました。
* 方針:これまでの話題とは少し異なる視点ですが、いかに正しい方向へ歩むべきかを明確にするために、「方針」を用いる人はいませんか?「方針」を持っていれば目的地へ向かって進みやすくなります。また、方針がなければたまたま同じ場所に行っても仕方ありません。ここにも「行為」の要素が入っていることに気付くと同時に、「手段」と「目的」が入れ替わっただけではないでしょうか?
強化学習は、最終的なゴールに向けて最適制御法を求めるという立場で考えられているので、この際に使われる単語が「制御可能」というものです。
--- 参照ドキュメント ---
1. ソース: /content/Reinforcement Learning An Introduction Second edition.pdf
内容抜粋: 74 CHAPTER 3. FINITE MARKOV DECISION PROCESSES Q*(s, driver) Vputt s a n d green !1 s a n d !2!2 !3 !4 !1 !5 !6 !4 !3 !3 !2 !4 s a n d green !1 s a n d !2 !3 !2 0 0 !" !" vputt q*(s,driver) Figure 3.6...
2. ソース: /content/Reinforcement Learning An Introduction Second edition.pdf
内容抜粋: because it has never received any relevant sensations. In short, we don’t fault an agent for not knowing something that matters, but only for having known something and then forgotten it! What we woul...
3. ソース: /content/Reinforcement Learning An Introduction Second edition.pdf
内容抜粋: π(a|s) probability of taking action a in state s under stochastic policy π p(s′,r|s,a) probability of transitioning to state s′, with reward r, from s,a vπ(s) value of state s under policy π (expected...