Download main.py from DROIDAIdev/DROIDAI: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/DROIDAIdev/DROIDAI/resolve/main/main.py
- Command line
-
hf download hf://DROIDAIdev/DROIDAI/main.py
-
curl -L -o main.py https://huggingface.co/DROIDAIdev/DROIDAI/resolve/main/main.py
1.39 kB
| import numpy as np | |
| def encode_to_variables(seed_sentence): | |
| counter = 0 | |
| global key, query_value, v | |
| key = np.random.uniform(0, 1) | |
| query_value = np.random.uniform(0, 1) | |
| updated_values = {} | |
| final_output = 0.0 | |
| for char in seed_sentence: | |
| ascii_code = ord(char) | |
| k_var_name = f"k_char_{chr(counter + 65)}" | |
| q_var_name = f"q_char_{chr(counter + 65)}" | |
| v_var_name = f"v_char_{chr(counter + 65)}" | |
| a_var_name = f"a_char_{chr(counter + 65)}" | |
| encoded_values = {} | |
| encoded_values[k_var_name] = ascii_code * key | |
| encoded_values[q_var_name] = ascii_code * query_value | |
| product = encoded_values[k_var_name] * encoded_values[q_var_name] | |
| clipped_product = np.clip(product, -10, 10) | |
| softmax_output = np.exp(clipped_product) / (np.exp(clipped_product) + 1) | |
| v = np.random.uniform(0, 1) | |
| updated_value = v * softmax_output + encoded_values[q_var_name] | |
| updated_values[a_var_name] = ascii_code + updated_value | |
| final_output += updated_values[a_var_name] | |
| counter += 1 | |
| final_output = int(final_output / 5.0) | |
| output = chr(final_output) | |
| return updated_values, output | |
| seed_sentence = input("Enter a seed sentence: ") | |
| encoded_values, output = encode_to_variables(seed_sentence) | |
| print(f"Next word (character): {output}") | |
| print(f"key : {key}") | |
| print(f"query_value : {query_value}") | |
| print(f"value: {v}") |