File size: 1,658 Bytes
8206c12
 
 
4083497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
license: mit
---

how to use model with gpt4all


import pandas as pd
from datasets import load_dataset
import re
csv_file = "/Users/admin/Downloads/GPT4_output_GPT-2_training_df.csv"
# Load the dataset
dataset = load_dataset("csv", data_files=csv_file, split="train")

def stop_on_token_callback(token_id, token_string):
    # one sentence is enough:
    if '<eos>' in token_string:
        return False
    else:
        return True

alpaca_prompt = """Below is an instruction that describes a task, paired with an 
input that provides further context. Write a response that appropriately completes 
the request.
### Instruction:
Find out which character said this specific quote along with their gender
### Input:
{}
### Response:
{}"""
num_examples=10
from gpt4all import GPT4All
model = GPT4All('/Users/admin/Downloads/model-unsloth.Q4_K_M.gguf')
system_template = '''Below is an instruction that describes a task, paired with an 
input that provides further context. Write a response that appropriately completes 
the request.'''
# many models use triple hash '###' for keywords, Vicunas are simpler:
prompt_template = """### Instruction:
Find out which character said this specific quote along with their gender
### Input:
{0}
### Response:
"""
with model.chat_session(system_template, prompt_template):
    for i in range(min(num_examples, len(dataset))):
        row = dataset[i]
        #response1 = model.generate(row['formatted_input'], callback=stop_on_token_callback)
        print(i)
        response1 = model.generate(row['formatted_input'])
        print(response1)
        print()
        print(f"Correct output: {row['TrueSpeaker']}")