sto provando a usare bertopic co llama2 come representationmodel attraverso l'uso di…
- User
sto provando a usare bertopic co llama2 come representation_model attraverso l'uso di questo codice from huggingface_hub import notebook_login notebook_login()
from torch import cuda
model_id = 'meta-llama/Llama-2-7b-chat-hf' device = f'cuda:{cuda.current_device()}' if cuda.is_available() else 'cpu'
print(device)
from torch import bfloat16 import transformers
set quantization configuration to load large model with less GPU memory
this requires the
bitsandbyteslibrarybnb_config = transformers.BitsAndBytesConfig( load_in_4bit=True, # 4-bit quantization bnb_4bit_quant_type='nf4', # Normalized float 4 bnb_4bit_use_double_quant=True, # Second quantization after the first bnb_4bit_compute_dtype=bfloat16 # Computation type )
Llama 2 Tokenizer
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
Llama 2 Model
model = transformers.AutoModelForCausalLM.from_pretrained( model_id, trust_remote_code=True, quantization_config=bnb_config, device_map='auto', ) model.eval()
Our text generator
generator = transformers.pipeline( model=model, tokenizer=tokenizer, task='text-generation', temperature=0.1, max_new_tokens=500, repetition_penalty=1.1 )
System prompt describes information given to all conversations
system_prompt = """ [INST] <> You are a helpful, respectful and honest assistant for labeling topics. <> """
Example prompt demonstrating the output we are looking for
example_prompt = """ I have a topic that contains the following documents:
- Traditional diets in most cultures were primarily plant-based with a little meat on top, but with the rise of industrial style meat production and factory farming, meat has become a staple food.
- Meat, but especially beef, is the word food in terms of emissions.
- Eating meat doesn't make you a bad person, not eating meat doesn't make you a good one.
The topic is described by the following keywords: 'meat, beef, eat, eating, emissions, steak, food, health, processed, chicken'.
Based on the information about the topic above, please create a short label of this topic. Make sure you to only return the label and nothing more.
[/INST] Environmental impacts of eating meat """
Our main prompt with documents ([DOCUMENTS]) and keywords ([KEYWORDS]) tags
main_prompt = """ [INST] I have a topic that contains the following documents: [DOCUMENTS]
The topic is described by the following keywords: '[KEYWORDS]'.
Based on the information about the topic above, please create a short label of this topic. Make sure you to only return the label and nothing more. [/INST] """
prompt = system_prompt + example_prompt + main_prompt
- Assistant