gabrielkyebambo commited on
Commit
1d34f0e
·
verified ·
1 Parent(s): b6f2b04

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +343 -36
README.md CHANGED
@@ -1,12 +1,23 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
  # Model Card for Model ID
7
 
8
  <!-- Provide a quick summary of what the model is/does. -->
9
-
 
 
10
 
11
 
12
  ## Model Details
@@ -14,16 +25,16 @@ tags: []
14
  ### Model Description
15
 
16
  <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
  - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
  ### Model Sources [optional]
29
 
@@ -35,23 +46,26 @@ This is the model card of a 🤗 transformers model that has been pushed on the
35
 
36
  ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
  ### Direct Use
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
 
45
 
46
  ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
 
51
 
52
  ### Out-of-Scope Use
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
 
 
55
 
56
  [More Information Needed]
57
 
@@ -69,21 +83,187 @@ Users (both direct and downstream) should be made aware of the risks, biases and
69
 
70
  ## How to Get Started with the Model
71
 
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  ## Training Details
77
 
78
  ### Training Data
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
 
 
81
 
82
- [More Information Needed]
 
 
 
 
83
 
84
  ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
 
87
 
88
  #### Preprocessing [optional]
89
 
@@ -92,11 +272,36 @@ Use the code below to get started with the model.
92
 
93
  #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  #### Speeds, Sizes, Times [optional]
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
 
 
 
 
100
 
101
  [More Information Needed]
102
 
@@ -108,7 +313,10 @@ Use the code below to get started with the model.
108
 
109
  #### Testing Data
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
 
 
 
112
 
113
  [More Information Needed]
114
 
@@ -121,16 +329,110 @@ Use the code below to get started with the model.
121
  #### Metrics
122
 
123
  <!-- These are the evaluation metrics being used, ideally with a description of why. -->
 
 
 
 
 
124
 
125
  [More Information Needed]
126
 
127
  ### Results
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  [More Information Needed]
130
 
131
  #### Summary
132
-
133
-
 
134
 
135
  ## Model Examination [optional]
136
 
@@ -144,9 +446,9 @@ Use the code below to get started with the model.
144
 
145
  Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
 
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
  - **Compute Region:** [More Information Needed]
151
  - **Carbon Emitted:** [More Information Needed]
152
 
@@ -174,7 +476,12 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
174
 
175
  **BibTeX:**
176
 
177
- [More Information Needed]
 
 
 
 
 
178
 
179
  **APA:**
180
 
@@ -196,4 +503,4 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
196
 
197
  ## Model Card Contact
198
 
199
- [More Information Needed]
 
1
  ---
2
  library_name: transformers
3
+ tags:
4
+ - service robotics
5
+ - llm
6
+ - taskplan generation
7
+ - llama instruct taskplans
8
+ license: apache-2.0
9
+ language:
10
+ - en
11
+ base_model:
12
+ - meta-llama/Llama-3.2-3B-Instruct
13
  ---
14
 
15
  # Model Card for Model ID
16
 
17
  <!-- Provide a quick summary of what the model is/does. -->
18
+ This model is a transformer-based neural network designed to generate safe and efficient task plans for robotic operations.
19
+ It translates human instructions into detailed task plans in JSON format, ensuring that tasks are executed safely and efficiently.
20
+ The model incorporates spatial relationships, safety constraints, and performance metrics to provide comprehensive and contextually relevant task plans for robotic systems.
21
 
22
 
23
  ## Model Details
 
25
  ### Model Description
26
 
27
  <!-- Provide a longer summary of what this model is. -->
28
+ This model is a transformer-based neural network specifically designed to generate safe and efficient task plans for robotic operations. It takes human instructions as input and outputs detailed task plans in JSON format, which include spatial relationships, task planning steps, and performance metrics.
29
+ The model is particularly useful for applications where precise and safe robotic manipulation is required, such as in manufacturing, service robotics, and automation.
30
+
31
+ - **Developed by:** Shaanxi University of Science and Technology/Fehead
32
+ - **Funded by [optional]:** Shaanxi Provincial Department of Education Service Local Special Plan Project (22JC019)
33
+ - **Shared by [optional]:** Shaanxi University of Science and Technology/Fehead
34
+ - **Model type:** Transformer
35
+ - **Language(s) (NLP):** English
36
  - **License:** [More Information Needed]
37
+ - **Finetuned from model [optional]:** meta-llama/Llama-3.2-3B-Instruct
38
 
39
  ### Model Sources [optional]
40
 
 
46
 
47
  ## Uses
48
 
 
 
49
  ### Direct Use
50
 
51
+ The model can be used directly for generating task plans for robotic operations based on human instructions. This is particularly useful in scenarios where precise and safe robotic manipulation is required. The model takes a human instruction as input and outputs a detailed task plan in JSON format, which includes spatial relationships, task planning steps, and performance metrics. This makes it suitable for applications in:
52
+ Manufacturing: Automating repetitive tasks and improving efficiency.
53
+ Service Robotics: Assisting in tasks such as cleaning, object retrieval, and placement.
54
+ Automation: Enhancing the capabilities of automated systems in various industries.
55
 
56
  ### Downstream Use [optional]
57
 
58
+ The model can be fine-tuned or integrated into larger systems for more specialized applications. For example:
59
+ Custom Task Planning: Fine-tuning the model on specific tasks or environments to improve accuracy and relevance.
60
+ Robotic Control Systems: Integrating the model into robotic control systems to provide real-time task planning and execution.
61
+ Human-Robot Interaction: Enhancing interaction systems where robots need to understand and execute human instructions accurately.
62
 
63
  ### Out-of-Scope Use
64
 
65
+ While the model is designed for generating safe and efficient task plans, it is important to note its limitations and potential misuse:
66
+ Misuse: The model should not be used in scenarios where the safety constraints are not applicable or where the environment is significantly different from the training data.
67
+ Limitations: The model's performance may degrade in environments with high variability or in tasks that require highly specialized knowledge not covered in the training data.
68
+ Ethical Considerations: Users should ensure that the model is used ethically and responsibly, avoiding any scenarios that could lead to harm or unethical behavior.
69
 
70
  [More Information Needed]
71
 
 
83
 
84
  ## How to Get Started with the Model
85
 
86
+ To get started with the model, you can use the following code to load the model, generate task plans based on human instructions, and parse the output. This example demonstrates how to run the fine-tuned model locally.
87
+ Prerequisites
88
+ Ensure you have the necessary dependencies installed. You can install them using pip:
89
+
90
+ pip install transformers torch
91
+
92
+ Below is an example of how to run the fine-tuned model locally to generate task plans based on human instructions:
93
+
94
+ import os
95
+ import json
96
+ import torch
97
+ from textwrap import dedent
98
+ from typing import Dict, List, Optional, Union, Any
99
+ from functools import lru_cache
100
+
101
+ from transformers import (
102
+ AutoModelForCausalLM,
103
+ AutoTokenizer,
104
+ pipeline,
105
+ Pipeline
106
+ )
107
+
108
+ class ModelManager:
109
+ def __init__(self, model_name: str):
110
+ self.model_name = model_name
111
+ self.tokenizer = None
112
+ self.model = None
113
+ self.pipe = None
114
+
115
+ @lru_cache(maxsize=1)
116
+ def get_tokenizer(self):
117
+ """Load tokenizer if not already loaded."""
118
+ if self.tokenizer is None:
119
+ self.tokenizer = AutoTokenizer.from_pretrained(self.model_name)
120
+ return self.tokenizer
121
+
122
+ def load_model(self):
123
+ """Load the model with proper error handling and performance optimizations."""
124
+ try:
125
+ if self.model is None:
126
+ self.model = AutoModelForCausalLM.from_pretrained(
127
+ self.model_name,
128
+ torch_dtype=torch.float16,
129
+ device_map="auto",
130
+ # Add performance optimizations
131
+ low_cpu_mem_usage=True,
132
+ offload_folder="offload",
133
+ )
134
+
135
+ tokenizer = self.get_tokenizer()
136
+ current_embed_size = self.model.get_input_embeddings().weight.size(0)
137
+ if len(tokenizer) != current_embed_size:
138
+ self.model.resize_token_embeddings(len(tokenizer), pad_to_multiple_of=8)
139
+
140
+ return self.model
141
+ except Exception as e:
142
+ raise RuntimeError(f"Failed to load model: {str(e)}") from e
143
+
144
+ def get_pipeline(self) -> Pipeline:
145
+ """Get or create the generation pipeline with optimized settings."""
146
+ if self.pipe is None:
147
+ model = self.load_model()
148
+ tokenizer = self.get_tokenizer()
149
+ self.pipe = pipeline(
150
+ task="text-generation",
151
+ model=model,
152
+ tokenizer=tokenizer,
153
+ max_new_tokens=1000, # Increased for longer responses
154
+ return_full_text=False,
155
+ # Add performance settings
156
+ batch_size=1,
157
+ num_workers=4,
158
+ )
159
+ return self.pipe
160
+
161
+ def create_prompt(self, user_input: str) -> str:
162
+ """Create a formatted prompt for the model."""
163
+ prompt = dedent(f"""
164
+ Instruction:
165
+ {user_input}
166
+
167
+ Please provide the response in a valid JSON format with spatial_relationships, task_plan, and performance_metrics.
168
+ """)
169
+
170
+ messages = [
171
+ {
172
+ "role": "system",
173
+ "content": "Generate a task plan in JSON format with spatial relationships, task planning, and performance metrics.",
174
+ },
175
+ {"role": "user", "content": prompt},
176
+ ]
177
+
178
+ return self.get_tokenizer().apply_chat_template(
179
+ messages, tokenize=False, add_generation_prompt=True
180
+ )
181
+
182
+ def parse_json_response(self, text: str) -> Dict[str, Any]:
183
+ """Parse the model output into a JSON object."""
184
+ try:
185
+ # Clean up the text to extract just the JSON part
186
+ # Find the first '{' and last '}'
187
+ start_idx = text.find('{')
188
+ end_idx = text.rfind('}') + 1
189
+
190
+ if start_idx == -1 or end_idx == 0:
191
+ raise ValueError("No JSON object found in response")
192
+
193
+ json_str = text[start_idx:end_idx]
194
+
195
+ # Parse the JSON
196
+ return json.loads(json_str)
197
+ except json.JSONDecodeError as e:
198
+ raise ValueError(f"Failed to parse JSON: {str(e)}\nOriginal text: {text}")
199
+
200
+ def generate(self, prompt: str) -> Dict[str, Any]:
201
+ """Generate and parse response for a given prompt."""
202
+ try:
203
+ pipe = self.get_pipeline()
204
+ outputs = pipe(prompt)
205
+ raw_response = outputs[0]["generated_text"]
206
+ # return self.parse_json_response(raw_response)
207
+ return raw_response
208
+ except Exception as e:
209
+ raise RuntimeError(f"Generation failed: {str(e)}") from e
210
+
211
+ def save_response(response: Dict[str, Any], filename: str = "response.json"):
212
+ """Save the response to a JSON file."""
213
+ with open(filename, 'w') as f:
214
+ json.dump(response, f, indent=2)
215
+
216
+ def main():
217
+ model_name = "gabrielkyebambo/Llama-3.2-3B-Instruct-TaskPlans"
218
+ manager = ModelManager(model_name)
219
+
220
+ try:
221
+ while True:
222
+ user_input = input('Enter prompt (or "quit" to exit): ')
223
+ if user_input.lower() == 'quit':
224
+ break
225
+
226
+ prompt = manager.create_prompt(user_input)
227
+ print(f'\nFormatted prompt:\n{prompt}\n')
228
+
229
+ response = manager.generate(prompt)
230
+
231
+ # Save response to file
232
+ save_response(response)
233
+
234
+ # Pretty print the response
235
+ print("\nGenerated task plan (formatted):")
236
+ print(json.dumps(response, indent=2))
237
+
238
+ except KeyboardInterrupt:
239
+ print("\nExiting gracefully...")
240
+ except Exception as e:
241
+ print(f"An error occurred: {str(e)}")
242
+
243
+ if __name__ == "__main__":
244
+ main()
245
 
246
  ## Training Details
247
 
248
  ### Training Data
249
 
250
+ The model was trained on a dataset consisting of 28,715 human instructions paired with corresponding task plans. The dataset is divided into training, validation, and test sets as follows:
251
+ Training set size: 22,972 examples
252
+ Validation set size: 4,594 examples
253
+ Test set size: 1,149 examples
254
 
255
+ Each example in the dataset includes the following features:
256
+ instruction: Human instruction in natural language.
257
+ task_plan: Corresponding task plan in JSON format.
258
+ text: Combined text of instruction and task plan.
259
+ token_count: Number of tokens in the text.
260
 
261
  ### Training Procedure
262
 
263
+ Preprocessing
264
+ Tokenization: Human instructions and task plans were tokenized using the Hugging Face tokenizer.
265
+ Normalization: Text data was normalized to ensure consistency.
266
+ Augmentation: Additional synthetic data was generated to cover edge cases and improve robustness.
267
 
268
  #### Preprocessing [optional]
269
 
 
272
 
273
  #### Training Hyperparameters
274
 
275
+ - **Training regime:**
276
+ - fp16 mixed precision
277
+ Batch size: 4 (per device)
278
+ Evaluation batch size: 1 (per device)
279
+ Gradient accumulation steps: 2
280
+ Optimizer: paged_adamw_8bit
281
+ Learning rate: 3e-4
282
+ Number of epochs: 3
283
+ Max sequence length: 1024
284
+ Evaluation strategy: steps
285
+ Evaluation steps: 0.2 (20% of training steps)
286
+ Save steps: 0.2 (20% of training steps)
287
+ Logging steps: 10
288
+ Warmup ratio: 0.1
289
+ Save total limit: 2
290
+ Learning rate scheduler: cosine
291
+ Reporting: tensorboard
292
+ Save safetensors: True
293
+ Max gradient norm: 0.5
294
+ Dataset kwargs:
295
+ add_special_tokens: False
296
+ append_concat_token: False
297
 
298
  #### Speeds, Sizes, Times [optional]
299
 
300
+ Training time: 27 hours
301
+ Hardware used: Single GPU (4060 TI 16GB)
302
+ Checkpoint size: [Specify Checkpoint Size]
303
+ Total parameters: 3,261,402,112
304
+ Trainable parameters: 48,627,712 (1.4910% of total parameters)
305
 
306
  [More Information Needed]
307
 
 
313
 
314
  #### Testing Data
315
 
316
+ Testing Data
317
+ The model was evaluated on a separate test dataset consisting of 1,149 human instructions and corresponding task plans.
318
+
319
+ Energy consumption: [Specify Average Energy Consumption]
320
 
321
  [More Information Needed]
322
 
 
329
  #### Metrics
330
 
331
  <!-- These are the evaluation metrics being used, ideally with a description of why. -->
332
+ Metrics
333
+ Accuracy: 98
334
+ Safety Compliance: 95
335
+ Efficiency Metrics: 97
336
+
337
 
338
  [More Information Needed]
339
 
340
  ### Results
341
 
342
+ Human Instruction: "go to the dining room, pick up the mug from the dining table, then take it to the kitchen and put it inside the sink"
343
+
344
+ Formatted prompt:
345
+ <|begin_of_text|><|start_header_id|>system<|end_header_id|>
346
+
347
+ Cutting Knowledge Date: December 2023
348
+ Today Date: 02 Feb 2025
349
+
350
+ Generate a task plan in JSON format with spatial relationships, task planning, and performance metrics.<|eot_id|><|start_header_id|>user<|end_header_id|>
351
+
352
+ Instruction:
353
+ go to the dinning room, pick up the mug from the dinning table, then take it to the kitchen and put it inside the sink
354
+
355
+ Please provide the response in a valid JSON format with spatial_relationships, task_plan, and performance_metrics.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
356
+
357
+ {
358
+ "spatial_relationships": {
359
+ "object": "mug",
360
+ "source": {
361
+ "location": "dining room",
362
+ "container_or_surface": "dining table",
363
+ "height": "0.05m",
364
+ "weight_range": [0.2, 0.3],
365
+ "grip_type": "power"
366
+ },
367
+ "destination": {
368
+ "location": "kitchen",
369
+ "container_or_surface": "sink",
370
+ "height": "0.95m",
371
+ "weight_range": [0.1, 0.2],
372
+ "grip_type": "power"
373
+ },
374
+ "navigation_constraints": {
375
+ "min_obstacle_distance": "0.7m",
376
+ "max_velocity": "1.0m/s",
377
+ "max_acceleration": "1.0m/s²"
378
+ },
379
+ "task_constraints": {
380
+ "success_criteria": [
381
+ "navigation_completed_safely",
382
+ "object_grasped_securely",
383
+ "object_transported_safely",
384
+ "object_placed_correctly"
385
+ ],
386
+ "safety_constraints": {
387
+ "collision_avoidance": "active",
388
+ "force_limits": {
389
+ "grasp_force": "24.08N",
390
+ "transport_force": "17.17N",
391
+ "placement_force": "2.45N"
392
+ },
393
+ "height_constraints": {
394
+ "min_height": "0.05m",
395
+ "max_height": "0.95m"
396
+ },
397
+ "orientation_constraints": {
398
+ "object_stability": "high",
399
+ "table_surface_stability": "high"
400
+ }
401
+ }
402
+ },
403
+ "performance_metrics": {
404
+ "success_criteria": [
405
+ "navigation_completed_safely",
406
+ "object_grasped_securely",
407
+ "object_transported_safely",
408
+ "object_placed_correctly"
409
+ ],
410
+ "safety_metrics": {
411
+ "collision_avoidance": "verified",
412
+ "force_limits_maintained": "verified",
413
+ "height_constraints_maintained": "verified",
414
+ "orientation_constraints_maintained": "verified"
415
+ },
416
+ "estimated_metrics": {
417
+ "total_distance": "13.6m",
418
+ "estimated_time": "59s",
419
+ "energy_consumption": "18.3Wh"
420
+ },
421
+ "critical_monitoring": [
422
+ "object_tracking",
423
+ "force_feedback",
424
+ "obstacle_detection"
425
+ ]
426
+ }
427
+ }
428
+ }
429
+
430
  [More Information Needed]
431
 
432
  #### Summary
433
+ This model provides a robust solution for generating task plans for robotic operations, ensuring safety and efficiency. It is suitable for applications in manufacturing, service robotics, and automation. For more detailed information, refer to the full model card.
434
+ The dataset for the model is currently being expanded to include a broader range of human instructions for robotic operations. This expansion aims to enhance the model's ability to handle more diverse and complex tasks in human-robot collaboration scenarios.
435
+ The new dataset will cover various manufacturing tasks, including assembly, disassembly, and maintenance operations, to improve the model's generalization and adaptability
436
 
437
  ## Model Examination [optional]
438
 
 
446
 
447
  Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
448
 
449
+ - **Hardware Type:** NVIDIA 4060 TI 16GB GPU.
450
+ - **Hours used:** > 27 hours
451
+ - **Cloud Provider:** Trained locally
452
  - **Compute Region:** [More Information Needed]
453
  - **Carbon Emitted:** [More Information Needed]
454
 
 
476
 
477
  **BibTeX:**
478
 
479
+ @article{qi2024safety,
480
+ title={Safety Control of Service Robots with LLMs and Embodied Knowledge Graphs},
481
+ author={Qi, Yong and Kyebambo, Gabriel and Xie, Siyuan and Shen, Wei and Wang, Shenghui and Xie, Bitao and He, Bin and Wang, Zhipeng and Jiang, Shuo},
482
+ journal={arXiv preprint arXiv:2405.17846},
483
+ year={2024}
484
+ }
485
 
486
  **APA:**
487
 
 
503
 
504
  ## Model Card Contact
505
 
506