SpeedStar101 commited on
Commit
e66fc88
1 Parent(s): 41f3c42

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +89 -0
README.md CHANGED
@@ -38,6 +38,95 @@ While VergilGPT2 showcases impressive conversational capabilities, it is importa
38
 
39
  Unleash the power of VergilGPT2 and immerse yourself in dynamic and captivating conversations that push the boundaries of interactive AI experiences. Let the conversations unfold and discover the true potential of this extraordinary model.
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  ## Installation
42
 
43
  Make sure to install the required dependencies by running the following commands:
 
38
 
39
  Unleash the power of VergilGPT2 and immerse yourself in dynamic and captivating conversations that push the boundaries of interactive AI experiences. Let the conversations unfold and discover the true potential of this extraordinary model.
40
 
41
+ ## Engaging with Vergil
42
+ If you're eager to have a conversation with VergilGPT2, you can utilize the following code snippet. Feel free to experiment with the variables 'temperature', 'top_k', 'top_p', to customize the response generation according to your preferences.
43
+
44
+ ```python
45
+ import torch
46
+ import re
47
+ import random
48
+ from transformers import AutoTokenizer, AutoModelForCausalLM
49
+
50
+ def filter_english_words(text):
51
+ # Initialize an empty list to store the filtered words
52
+ filtered_text = []
53
+ # Split the input text into individual words
54
+ words = text.split()
55
+ # Iterate through the words
56
+ for word in words:
57
+ # Check if the word is a valid English word or a punctuation
58
+ if word.isalpha() or re.match(r'^[!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~]$', word):
59
+ # If it is, append it to the filtered text list
60
+ filtered_text.append(word)
61
+ # Return the filtered text as a string
62
+ return ' '.join(filtered_text)
63
+
64
+ def generate_response(model, tokenizer, input_text, max_length=300, min_length=20, num_return_sequences=1, temperature=0.2, top_k=50, top_p=0.9, num_beams=10, repetition_penalty=1.0):
65
+ input_ids = tokenizer.encode(input_text, return_tensors='pt')
66
+
67
+ # Set model to eval mode
68
+ model.eval()
69
+
70
+ # Generate responses using different decoding strategies
71
+ try:
72
+ output = model.generate(
73
+ input_ids=input_ids,
74
+ max_length=max_length,
75
+ min_length=min_length,
76
+ num_return_sequences=num_return_sequences,
77
+ temperature=temperature,
78
+ top_k=top_k,
79
+ top_p=top_p,
80
+ num_beams=num_beams,
81
+ no_repeat_ngram_size=2,
82
+ do_sample=True,
83
+ repetition_penalty=repetition_penalty # Added repetition_penalty
84
+ )
85
+
86
+ # Decode the generated responses
87
+ responses = [tokenizer.decode(o, skip_special_tokens=True) for o in output]
88
+ # Remove input_text from the responses
89
+ responses = [response[len(tokenizer.decode(input_ids[0], skip_special_tokens=True)):] for response in responses]
90
+
91
+ # Filter out non-English words
92
+ responses = [filter_english_words(response) for response in responses]
93
+
94
+ return responses
95
+
96
+ except RuntimeError:
97
+ return ["I'm sorry, I encountered an error while generating a response."]
98
+
99
+
100
+ # Load pre-trained model and tokenizer
101
+ access_token = "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"
102
+ model_id = "Starcodium/VergilGPT2"
103
+ tokenizer = AutoTokenizer.from_pretrained(model_id, revision="main", use_auth_token=access_token)
104
+ model = AutoModelForCausalLM.from_pretrained(model_id, revision="main", use_auth_token=access_token)
105
+
106
+ tokenizer.pad_token = tokenizer.eos_token
107
+ model.config.pad_token_id = model.config.eos_token_id
108
+
109
+ # Get user input and generate responses
110
+ while True:
111
+ input_text = input("Type 'quit' or 'exit' to stop runtime.\nEnter your input text: ")
112
+ if input_text.lower() in ["quit", "exit"]:
113
+ break
114
+
115
+ responses = generate_response(model, tokenizer, input_text, max_length=100, min_length=20, num_return_sequences=1, temperature=0.7, top_k=40, top_p=0.5, num_beams=1, repetition_penalty=1.2)
116
+ responses = [r for r in responses if r.strip() != '']
117
+ if responses:
118
+ response = responses[0]
119
+ else:
120
+ response = "I'm sorry, I don't have a response at the moment."
121
+
122
+ # Print the bot's response
123
+ print("Vergil: "+response)
124
+ ```
125
+
126
+ This code snippet allows you to engage in conversations with VergilGPT2. Simply enter your input text, and VergilGPT2 will generate responses based on the provided context. Experiment with different values of the variables temperature, top_k, and top_p to customize the response generation process according to your desired preferences.
127
+
128
+ Please note that the code assumes you have access to the Starcodium/VergilGPT2 model and its associated tokenizer. Ensure you have the required authentication token (access_token) to access the model and tokenizer.
129
+
130
  ## Installation
131
 
132
  Make sure to install the required dependencies by running the following commands: