Update README.md
Browse files
README.md
CHANGED
|
@@ -35,7 +35,68 @@ This is the model card of a 🤗 transformers model that has been pushed on the
|
|
| 35 |
|
| 36 |
## Uses
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
### Direct Use
|
| 41 |
|
|
|
|
| 35 |
|
| 36 |
## Uses
|
| 37 |
|
| 38 |
+
use under gen function to parse output from the LLM
|
| 39 |
+
Loaded function of LLM is as the same as other LLM
|
| 40 |
+
|
| 41 |
+
import re
|
| 42 |
+
|
| 43 |
+
def gen(x):
|
| 44 |
+
system_prompt = f"""
|
| 45 |
+
Make a trading decision based on the following data.
|
| 46 |
+
Please respond with a JSON object in the following format:
|
| 47 |
+
{{"investment_decision": string, "summary_reason": string, "short_memory_index": number, "middle_memory_index": number, "long_memory_index": number, "reflection_memory_index": number}}
|
| 48 |
+
investment_decision must always be one of {{buy, sell, hold}}
|
| 49 |
+
Print the memory index value to 4 decimal places. If it exceeds, round up.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
# Tokenizing the input and generating the output
|
| 53 |
+
|
| 54 |
+
inputs = tokenizer(
|
| 55 |
+
[
|
| 56 |
+
f"system{system_prompt}user{x}"
|
| 57 |
+
], return_tensors = "pt").to("cuda")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
gened = model.generate(
|
| 61 |
+
**inputs,
|
| 62 |
+
max_new_tokens=256,
|
| 63 |
+
early_stopping=True,
|
| 64 |
+
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
full_text = tokenizer.decode(gened[0])
|
| 68 |
+
|
| 69 |
+
# Define possible start phrases
|
| 70 |
+
possible_start_phrases = ["{\"investment_decision\": \"buy\"", "{\"investment_decision\": \"sell\"", "{\"investment_decision\": \"hold\""]
|
| 71 |
+
start_idx = -1
|
| 72 |
+
|
| 73 |
+
# Find the index for the start phrase
|
| 74 |
+
for phrase in possible_start_phrases:
|
| 75 |
+
start_idx = full_text.find(phrase)
|
| 76 |
+
if start_idx != -1:
|
| 77 |
+
break
|
| 78 |
+
|
| 79 |
+
if start_idx == -1:
|
| 80 |
+
return "No valid investment decision found in the output."
|
| 81 |
+
|
| 82 |
+
# Find the index for the end phrase
|
| 83 |
+
end_phrase = "\"reflection_memory_index\":"
|
| 84 |
+
end_idx = full_text.find(end_phrase, start_idx)
|
| 85 |
+
|
| 86 |
+
if end_idx == -1:
|
| 87 |
+
return "No valid reflection_memory_index found in the output."
|
| 88 |
+
|
| 89 |
+
# Find the end of the reflection_memory_index value
|
| 90 |
+
end_idx = full_text.find('}', end_idx)
|
| 91 |
+
if end_idx == -1:
|
| 92 |
+
return "No closing bracket found in the output."
|
| 93 |
+
|
| 94 |
+
# Extract the text between start_idx and end_idx
|
| 95 |
+
extracted_text = full_text[start_idx:end_idx+1].strip()
|
| 96 |
+
|
| 97 |
+
return extracted_text
|
| 98 |
+
|
| 99 |
+
|
| 100 |
|
| 101 |
### Direct Use
|
| 102 |
|