Update README.md
Browse files
README.md
CHANGED
|
@@ -11,6 +11,65 @@ language:
|
|
| 11 |
- en
|
| 12 |
---
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Uploaded model
|
| 15 |
|
| 16 |
- **Developed by:** learn-abc
|
|
|
|
| 11 |
- en
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Fine-tuned TinyLlama for JSON Extraction
|
| 15 |
+
|
| 16 |
+
This repository contains a fine-tuned version of the `unsloth/tinyllama-chat-bnb-4bit` model, specifically trained for extracting product information from HTML snippets and outputting it in a JSON format.
|
| 17 |
+
|
| 18 |
+
## Model Details
|
| 19 |
+
|
| 20 |
+
- **Base Model:** `unsloth/tinyllama-chat-bnb-4bit`
|
| 21 |
+
- **Fine-tuning Method:** LoRA (Low-Rank Adaptation)
|
| 22 |
+
- **Trained on:** A custom dataset of HTML product snippets and their corresponding JSON representations.
|
| 23 |
+
|
| 24 |
+
## Usage
|
| 25 |
+
|
| 26 |
+
This model can be used for tasks involving structured data extraction from HTML content.
|
| 27 |
+
|
| 28 |
+
### Loading the model
|
| 29 |
+
|
| 30 |
+
You can load the model and tokenizer using the `transformers` library:
|
| 31 |
+
```python
|
| 32 |
+
from unsloth import FastLanguageModel
|
| 33 |
+
import torch
|
| 34 |
+
import json
|
| 35 |
+
|
| 36 |
+
model_name = "learn-abc/html-model-tinyllama-chat-bnb-4bit" # Replace with your actual repo ID
|
| 37 |
+
max_seq_length = 2048 # Or your chosen sequence length
|
| 38 |
+
dtype = None # Auto detection
|
| 39 |
+
|
| 40 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 41 |
+
model_name = model_name,
|
| 42 |
+
max_seq_length = max_seq_length,
|
| 43 |
+
dtype = dtype,
|
| 44 |
+
load_in_4bit = True,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
FastLanguageModel.for_inference(model)
|
| 48 |
+
|
| 49 |
+
messages = [
|
| 50 |
+
{"role": "user", "content": "Extract the product information:\n<div class='product'><h2>iPad Air</h2><span class='price'>$1344</span><span class='category'>audio</span><span class='brand'>Dell</span></div>"}
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
inputs = tokenizer.apply_chat_template(
|
| 54 |
+
messages,
|
| 55 |
+
tokenize=True,
|
| 56 |
+
add_generation_prompt=True,
|
| 57 |
+
return_tensors="pt",
|
| 58 |
+
).to("cuda") # Or "cpu" if not using GPU
|
| 59 |
+
|
| 60 |
+
outputs = model.generate(
|
| 61 |
+
input_ids=inputs,
|
| 62 |
+
max_new_tokens=256,
|
| 63 |
+
use_cache=True,
|
| 64 |
+
temperature=0.7,
|
| 65 |
+
do_sample=True,
|
| 66 |
+
top_p=0.9,
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
response = tokenizer.batch_decode(outputs)[0]
|
| 70 |
+
print(response)
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
# Uploaded model
|
| 74 |
|
| 75 |
- **Developed by:** learn-abc
|