Ey-luccas commited on
Commit
0188a3d
·
verified ·
1 Parent(s): 3b0b641

Create inference_tc.ipynb

Browse files

Este é o código básico para realizar inferência com o modelo treinado no Unstlho. O modelo apresenta algumas limitações devido ao conjunto de dados utilizado, que contém apenas informações básicas sobre plantio, sem uma ampla cobertura territorial, como as práticas agrícolas no Brasil.

Apesar dessas restrições, este é o modelo de maior sucesso dentro da equipe. Ele foi desenvolvido com base no unsloth/Llama-3.2-3B-Instruct-bnb-4bit e treinado utilizando o dataset "Solshine/Reflection-Tuning-Natural-Farming_Agricultural-Dataset".

Files changed (1) hide show
  1. inference_tc.ipynb +53 -0
inference_tc.ipynb ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import login
2
+ login(token="seu_token_aqui")
3
+
4
+ %%capture
5
+ !pip install unsloth transformers #dependência do modelo: biblioteca unsloth e transformers
6
+
7
+ from unsloth import FastLanguageModel
8
+ from transformers import TextStreamer
9
+
10
+ def initialize_model():
11
+ model, tokenizer = FastLanguageModel.from_pretrained(
12
+ model_name="Ey-luccas/modelo_tc",
13
+ max_seq_length=10000,
14
+ dtype="float16",
15
+ load_in_4bit=True
16
+ )
17
+ FastLanguageModel.for_inference(model)
18
+ return model, tokenizer
19
+
20
+ def chat_with_model(model, tokenizer):
21
+ messages = [] # Histórico de mensagens
22
+ text_streamer = TextStreamer(tokenizer, skip_prompt=True)
23
+
24
+ print("\nBem-vindo ao Chat com o Modelo! Digite 'sair' para encerrar.\n")
25
+ while True:
26
+ user_input = input("Você: ")
27
+ if user_input.lower() == "sair":
28
+ print("Encerrando o chat. Até logo!")
29
+ break
30
+
31
+ messages.append({"role": "user", "content": user_input})
32
+
33
+ inputs = tokenizer.apply_chat_template(
34
+ messages,
35
+ tokenize=True,
36
+ add_generation_prompt=True,
37
+ return_tensors="pt",
38
+ ).to("cuda")
39
+
40
+ # Gera a resposta
41
+ print("Modelo:", end=" ")
42
+ _ = model.generate(
43
+ input_ids=inputs,
44
+ streamer=text_streamer,
45
+ max_new_tokens=10000,
46
+ use_cache=True,
47
+ temperature=1.0,
48
+ min_p=0.1
49
+ )
50
+
51
+ if __name__ == "__main__":
52
+ model, tokenizer = initialize_model()
53
+ chat_with_model(model, tokenizer)