Views
No views yet
ujjwal52/Llama-2-7b-chat-finetune-UK-Adv model, which was further fine-tuned using the Self-Play finetuning on Instruct (SPIN) approach( Fast APPROCH ). The original base model, Llama-2-7b-chat, was fine-tuned with data to specialize in generating responses relevant to the various context. This version benefits from 4-bit quantization, significantly reducing its memory footprint and enabling efficient deployment on resource-constrained environments, while maintaining much of its performance.Llama-2-7b-chat using legal , financial, advisory,chat data. It then underwent further refinement using the
**Self-Play finetuning on Instruct **
method, which allows the model to learn from its own generated responses and iteratively improve its instruction-following capabilities and response quality.transformers library, you can follow this example:1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
4# Define the model path on Hugging Face Hub
5model_name = "ujjwal52/Llama-2-7b-chat-UK-SPIN"
6
7# Configure 4-bit quantization
8bnb_config = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_compute_dtype=torch.float16,
12 bnb_4bit_use_double_quant=False
13)
14
15# Load the 4-bit quantized model and tokenizer
16model = AutoModelForCausalLM.from_pretrained(
17 model_name,
18 quantization_config=bnb_config,
19 device_map="auto"
20)
21tokenizer = AutoTokenizer.from_pretrained(model_name)
22
23# Example for text generation (using pipeline for simplicity)
24from transformers import pipeline
25
26prompt = "<s>[INST] What are the key differences between a solicitor and a barrister in the UK legal system? [/INST]"
27
28pipeline = pipeline(
29 task="text-generation",
30 model=model,
31 tokenizer=tokenizer,
32 max_new_tokens=500
33)
34
35result = pipeline(prompt)
36print(result[0]['generated_text'])
37
38# Clean up memory (optional)
39del model
40del tokenizer
41import gc
42import torch
43gc.collect()
44torch.cuda.empty_cache()1# Assuming the model and tokenizer are loaded as above
2
3prompt = "<s>[INST] Write a short explanation of the UK's 'Right to Roam' law. [/INST]"
4
5pipeline = pipeline(
6 task="text-generation",
7 model=model,
8 tokenizer=tokenizer,
9 max_new_tokens=200
10)
11
12result = pipeline(prompt)
13print(result[0]['generated_text'])<s>[INST] Write a short explanation of the UK's 'Right to Roam' law. [/INST] The 'Right to Roam' in the UK, formally known as the right of access to 'access land' under the Countryside and Rights of Way Act 2000 (CRoW Act), grants the public the right to walk freely over certain types of privately-owned land without needing to stick to paths. This includes mountains, moorland, heathland, downland, and registered common land.
However, this right comes with responsibilities and some limitations. For instance, you generally can't take vehicles onto access land, disturb wildlife, or damage property. There are also exclusions, such as cultivated land, gardens, and military byelaw land. Landowners can temporarily close areas for land management or safety reasons, and there are specific rules about dogs on access land.
In Scotland, the Land Reform (Scotland) Act 2003 grants a broader 'right of responsible access' to most land and inland water, provided it's exercised responsibly, respecting others' privacy, safety, and the environment. This is often seen as a more expansive right than that in England and Wales.bitsandbytes library.