Views
No views yet
<qt>, <p>, <o>, and <s>, we provide a detailed breakdown of each question's elements, which aids the model in grasping the roles of different components.
| Tag | Description |
|---|---|
<qt> | Question Type: Tags the keywords or phrases that denote the type of question being asked, such as 'What', 'Who', 'How many', etc. This tag helps determine the type of SPARQL query to generate. Example: In "What is the capital of Canada?", the tag <qt>What</qt> indicates that the question is asking for an entity retrieval. |
<o> | Object Entities: Tags entities that are objects in the question. These are usually noun phrases referring to the entities being described or queried. Example: In "What is the capital of Canada?", the term 'Canada' is tagged as <o>Canada</o>. |
<s> | Subject Entities: Tags entities that are subjects in Yes-No questions. This tag is used exclusively for questions that can be answered with 'Yes' or 'No'. Example: In "Is Ottawa the capital of Canada?", the entity 'Ottawa' is tagged as <s>Ottawa</s>. |
<p> | Predicates: Tags predicates that represent relationships or attributes in the knowledge graph. Predicates can be verb phrases or noun phrases that describe how entities are related. Example: In "What is the capital of Canada?", the phrase 'is the capital of' is tagged as <p>is the capital of</p>. |
<cc> | Coordinating Conjunctions: Tags conjunctions that connect multiple predicates or entities in complex queries. These include words like 'and', 'or', and 'nor'. They influence how the SPARQL query combines conditions. Example: In "Who is the CEO and founder of Apple Inc?", the conjunction 'and' is tagged as <cc>and</cc>. |
<off> | Offsets: Tags specific terms that indicate position or order in a sequence, such as 'first', 'second', etc. These are used in questions asking for ordinal positions. Example: In "What is the second largest country?", the word 'second' is tagged as <off>second</off>. |
<t> | Entity Types: Tags that describe the type or category of the entities involved in the question. This can include types like 'person', 'place', 'organization', etc. Example: In "Which film directed by Garry Marshall?", the type 'film' might be tagged as <t>film</t>. |
<op> | Operators: Tags operators used in questions that involve comparisons or calculations, such as 'greater than', 'less than', 'more than'. Example: In "Which country has a population greater than 50 million?", the operator 'greater than' is tagged as <op>greater than</op>. |
<ref> | References: Tags in questions that refer back to previously mentioned entities or concepts. These can indicate cycles or self-references in queries. Example: In "Who is the CEO of the company founded by himself?", the word 'himself' is tagged as <ref>himself</ref>. |
meta_model_0.pt file and the tokenizer. (see the files and versions tap in this page)./home/USERNAME/Meta-Llama-3-8B/USERNAME with your username.custom_generation_config_bigModel.yaml in /home/USERNAME/ with the following content:1# Config for running the InferenceRecipe in generate.py to generate output from an LLM
2
3# Model arguments
4model:
5 _component_: torchtune.models.llama3.llama3_8b
6
7checkpointer:
8 _component_: torchtune.utils.FullModelMetaCheckpointer
9 checkpoint_dir: /home/USERNAME/Meta-Llama-3-8B/
10 checkpoint_files: [
11 meta_model_0.pt
12 ]
13 output_dir: /home/USERNAME/Meta-Llama-3-8B/
14 model_type: LLAMA3
15
16device: cuda
17dtype: bf16
18
19seed: 1234
20
21# Tokenizer arguments
22tokenizer:
23 _component_: torchtune.models.llama3.llama3_tokenizer
24 path: /home/USERNAME/Meta-Llama-3-8B/original/tokenizer.model
25
26# Generation arguments; defaults taken from gpt-fast
27prompt: "### Instruction: \nYou are a powerful model trained to convert questions to tagged questions. Use the tags as follows: \n<qt> to surround question keywords like 'What', 'Who', 'Which', 'How many', 'Return' or any word that represents requests. \n<o> to surround entities as an object like person name, place name, etc. It must be a noun or a noun phrase. \n<s> to surround entities as a subject like person name, place name, etc. The difference between <s> and <o>, <s> only appear in yes/no questions as in the training data you saw before. \n<cc> to surround coordinating conjunctions that connect two or more phrases like 'and', 'or', 'nor', etc. \n<p> to surround predicates that may be an entity attribute or a relationship between two entities. It can be a verb phrase or a noun phrase. The question must contain at least one predicate. \n<off> for offset in questions asking for the second, third, etc. For example, the question 'What is the second largest country?', <off> will be located as follows. 'What is the <off>second</off> largest country?' \n<t> to surround entity types like person, place, etc. \n<op> to surround operators that compare quantities or values, like 'greater than', 'more than', etc. \n<ref> to indicate a reference within the question that requires a cycle to refer back to an entity (e.g., 'Who is the CEO of a company founded by himself?' where 'himself' would be tagged as <ref>himself</ref>). \nInput: Which films directed by a dirctor died in 2014 and starring both Julia Roberts and Richard Gere?\nResponse:"
28max_new_tokens: 100
29temperature: 0.6
30top_k: 1
31
32quantizer: null/home/USERNAME/myenvpip install torchtunecommand.py with the following content:1import subprocess
2import os
3import re
4import shlex # For safely handling command line arguments
5
6def _create_config_file(question):
7 # Path to the template and output config file
8 template_path = "/home/USERNAME/custom_generation_config_bigModel.yaml"
9 output_path = "/tmp/dynamic_generation.yaml"
10
11 # Load the template from the file
12 with open(template_path, 'r') as file:
13 config_template = file.read()
14
15 # Replace the placeholder in the template with the actual question
16 updated_prompt = config_template.replace("Input: Which films directed by a dirctor died in 2014 and starring both Julia Roberts and Richard Gere?", f"Input: {question}")
17 maxLen = int(1.3*len(question))
18 print(f"maxLen: {maxLen}")
19 updated_prompt = updated_prompt.replace("max_new_tokens: 100", f"max_new_tokens: {maxLen}")
20
21 # Write the updated configuration to a new file
22 with open(output_path, 'w') as file:
23 file.write(updated_prompt)
24
25 print(f"Configuration file created at: {output_path}")
26
27def get_tagged_question(question):
28 # Define the path to the virtual environment's activation script
29 activate_env = "/home/USERNAME/myenv/bin/activate"
30
31 # Create configuration file with the question
32 _create_config_file(question)
33
34 print('get_tagged_question')
35
36 # Command to run within the virtual environment
37 command = f"tune run generate --config /tmp/dynamic_generation.yaml"
38
39 # Full command to activate the environment and run your command
40 full_command = f"source {activate_env} && {command}"
41
42 # Run the full command in a shell
43 try:
44 result = subprocess.run(full_command, shell=True, check=True, text=True, capture_output=True, executable="/bin/bash")
45 print("Command output:", result.stdout)
46 print("Command error output:", result.stderr)
47
48 output = result.stdout + result.stderr
49 # Extract the input and response using modified regular expressions
50 input_match = re.search(r'Input: (.*?)(?=Response:)', output, re.S)
51 response_match = re.search(r'Response: (.*)', output)
52
53 response_match = response_match.group(1).strip()
54
55 if input_match and response_match:
56 print("Input Question: ", question)
57 print("Extracted Response: ", response_match)
58 else:
59 print("Input or Response not found in the output.")
60
61 except subprocess.CalledProcessError as e:
62 print("An error occurred:", e.stderr)
63 return response_match
64
65if __name__ == "__main__":
66 # Call the function with a sample question
67 get_tagged_question("Who is the president of largest country in Africa?")python command.pyMeta-Llama-3-8B model by two key steps: preparing the dataset and executing the fine-tuning process./home/YOUR_USERNAME/dataMeta-Llama-3-8B model, we leveraged Torchtune. Follow these steps to complete the process:<ACCESS TOKEN> with your actual Huggingface token and adjust the output directory as needed:1tune download \
2 meta-llama/Meta-Llama-3-8B \
3 --output-dir /home/YOUR_USERNAME/Meta-Llama-3-8B \
4 --hf-token <ACCESS TOKEN>tune cp llama3/8B_lora_single_device custom_config.yaml1# Config for single device LoRA finetuning in lora_finetune_single_device.py
2# using a Llama3 8B model
3#
4# Ensure the model is downloaded using the following command before launching:
5# tune download meta-llama/Meta-Llama-3-8B --output-dir /tmp/Meta-Llama-3-8B --hf-token <HF_TOKEN>
6#
7# To launch on a single device, run this command from the root directory:
8# tune run lora_finetune_single_device --config llama3/8B_lora_single_device
9#
10# You can add specific overrides through the command line. For example,
11# to override the checkpointer directory, use:
12# tune run lora_finetune_single_device --config llama3/8B_lora_single_device checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
13#
14# This config is for training on a single device.
15
16# Model Arguments
17model:
18 _component_: torchtune.models.llama3.lora_llama3_8b
19 lora_attn_modules: ['q_proj', 'v_proj']
20 apply_lora_to_mlp: False
21 apply_lora_to_output: False
22 lora_rank: 8
23 lora_alpha: 16
24
25# Tokenizer
26tokenizer:
27 _component_: torchtune.models.llama3.llama3_tokenizer
28 path: /home/YOUR_USERNAME/Meta-Llama-3-8B/original/tokenizer.model
29
30checkpointer:
31 _component_: torchtune.utils.FullModelMetaCheckpointer
32 checkpoint_dir: /home/YOUR_USERNAME/Meta-Llama-3-8B/original/
33 checkpoint_files: [
34 consolidated.00.pth
35 ]
36 recipe_checkpoint: null
37 output_dir: /home/YOUR_USERNAME/Meta-Llama-3-8B/
38 model_type: LLAMA3
39resume_from_checkpoint: False
40
41# Dataset and Sampler
42dataset:
43 _component_: torchtune.datasets.instruct_dataset
44 split: train
45 source: /home/YOUR_USERNAME/data
46 template: AlpacaInstructTemplate
47 train_on_input: False
48seed: null
49shuffle: True
50batch_size: 1
51
52# Optimizer and Scheduler
53optimizer:
54 _component_: torch.optim.AdamW
55 weight_decay: 0.01
56 lr: 3e-4
57lr_scheduler:
58 _component_: torchtune.modules.get_cosine_schedule_with_warmup
59 num_warmup_steps: 100
60
61loss:
62 _component_: torch.nn.CrossEntropyLoss
63
64# Training
65epochs: 1
66max_steps_per_epoch: null
67gradient_accumulation_steps: 64
68compile: False
69
70# Logging
71output_dir: /home/YOUR_USERNAME/lora_finetune_output
72metric_logger:
73 _component_: torchtune.utils.metric_logging.DiskLogger
74 log_dir: ${output_dir}
75log_every_n_steps: null
76
77# Environment
78device: cuda
79dtype: bf16
80enable_activation_checkpointing: True
81
82# Profiler (disabled)
83profiler:
84 _component_: torchtune.utils.profiler
85 enabled: Falsetune run lora_finetune_single_device --config /home/YOUR_USERNAME/.../custom_config.yaml/home/YOUR_USERNAME/Meta-Llama-3-8B/ directory.