Clemylia commited on
Commit
7a15d90
·
verified ·
1 Parent(s): 137f403

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +127 -1
README.md CHANGED
@@ -9,4 +9,130 @@ tags:
9
  - Les recettes loufoques
10
  - assemblage
11
  - fait moi une glace a la viande
12
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  - Les recettes loufoques
10
  - assemblage
11
  - fait moi une glace a la viande
12
+ ---
13
+
14
+ # 🍓 Ice-Clem 🍓
15
+
16
+ Bienvenue sur la documentation de l'IA : Ice-Clem.
17
+ ce petit modèle tres simple,
18
+ a été crée et entraîné en 5 minutes, en réponse a une idée éclair,
19
+ apparu lorsque j'étais assez fatiguée j'avoue 🤣.
20
+
21
+ Le but de ce modèle est de générer des combinaisons loufoques d'aliments qui ont rien a voir entre eux,
22
+ pour vous faire imaginer des plats dégueulasse et vous faire sourir (ou rire j'espère).
23
+
24
+ le modèle a ete entraîné sur certains mots-clés (les ingrédients),
25
+ et a partir d'un ingrédients de départ,
26
+ génère totalement aléatoirement la suite des ingrédients pour faire votre plat loufoque (a ne pas concrétiser).
27
+
28
+ les noms des ingrédients sont rédigés en anglais.
29
+
30
+ ## 🌸 Liste des ingrédients 🌸
31
+
32
+ Voici la listes des ingrédients de départ que vous pouvez utiliser :
33
+
34
+ pizza
35
+ sushi
36
+ pasta
37
+ soup
38
+ curry
39
+ steak
40
+ salad
41
+ burger
42
+ tacos
43
+ noodles
44
+ rice
45
+ bread
46
+ cake
47
+ cookies
48
+ pie
49
+ chocolate
50
+ vanilla
51
+ strawberry
52
+ spicy
53
+ sour
54
+
55
+ le modèle générera la suite, de façon aléatoire mais intelligente.
56
+ ;) 🔥
57
+
58
+ # 🩵 Exemple d'utilisation 🩵
59
+
60
+ ```
61
+ from huggingface_hub import hf_hub_download
62
+ import torch
63
+ import json
64
+ import os
65
+
66
+ # Define your Hugging Face repository name and the filenames
67
+ repo_name = "Clemylia/Ice-Clem" # Make sure this matches the repository name you used
68
+ model_filename = "pytorch_model.bin"
69
+ word_to_index_filename = "word_to_index.json"
70
+ index_to_word_filename = "index_to_word.json"
71
+
72
+ # Download the files from the Hugging Face Hub
73
+ try:
74
+ model_path = hf_hub_download(repo_id=repo_name, filename=model_filename)
75
+ word_to_index_path = hf_hub_download(repo_id=repo_name, filename=word_to_index_filename)
76
+ index_to_word_path = hf_hub_download(repo_id=repo_name, filename=index_to_word_filename)
77
+
78
+ print(f"Downloaded model to: {model_path}")
79
+ print(f"Downloaded word_to_index to: {word_to_index_path}")
80
+ print(f"Downloaded index_to_word to: {index_to_word_path}")
81
+
82
+ # Load the word_to_index and index_to_word mappings
83
+ with open(word_to_index_path, 'r') as f:
84
+ word_to_index = json.load(f)
85
+
86
+ with open(index_to_word_path, 'r') as f:
87
+ index_to_word = json.load(f)
88
+ # Convert keys back to integers if they were saved as strings
89
+ index_to_word = {int(k): v for k, v in index_to_word.items()}
90
+
91
+
92
+ # Define the model architecture (must match the architecture used for training)
93
+ # You'll need the same hyperparameters as before
94
+ vocab_size = len(word_to_index)
95
+ embedding_dim = 100 # Make sure this matches your training parameter
96
+ hidden_dim = 256 # Make sure this matches your training parameter
97
+ output_dim = vocab_size
98
+
99
+ class FoodCombinerModel(torch.nn.Module):
100
+ def __init__(self, vocab_size, embedding_dim, hidden_dim, output_dim):
101
+ super(FoodCombinerModel, self).__init__()
102
+ self.embedding = torch.nn.Embedding(vocab_size, embedding_dim)
103
+ self.lstm = torch.nn.LSTM(embedding_dim, hidden_dim, batch_first=True)
104
+ self.fc = torch.nn.Linear(hidden_dim, output_dim)
105
+
106
+ def forward(self, x):
107
+ embedded = self.embedding(x)
108
+ lstm_out, _ = self.lstm(embedded)
109
+ output = self.fc(lstm_out[:, -1, :])
110
+ return output
111
+
112
+ # Instantiate the model
113
+ loaded_model = FoodCombinerModel(vocab_size, embedding_dim, hidden_dim, output_dim)
114
+
115
+ # Load the saved state dictionary
116
+ loaded_model.load_state_dict(torch.load(model_path))
117
+
118
+ # Set the model to evaluation mode
119
+ loaded_model.eval()
120
+
121
+ print("Model loaded successfully!")
122
+
123
+ # Now you can use the loaded_model for generation
124
+ # Make sure the generate_combination function is defined in a previous cell and accessible
125
+
126
+ # Generate a combination using the loaded model
127
+ starting_phrase_loaded = "sushi" # You can use any word from your vocabulary
128
+ generated_combination_loaded = generate_combination(loaded_model, starting_phrase_loaded, word_to_index, index_to_word)
129
+ print(f"\nGenerated combination using loaded model starting with '{starting_phrase_loaded}': {generated_combination_loaded}")
130
+
131
+ starting_phrase_loaded_2 = "pizza"
132
+ generated_combination_loaded_2 = generate_combination(loaded_model, starting_phrase_loaded_2, word_to_index, index_to_word)
133
+ print(f"Generated combination using loaded model starting with '{starting_phrase_loaded_2}': {generated_combination_loaded_2}")
134
+
135
+ except Exception as e:
136
+ print(f"An error occurred: {e}")
137
+ print("Please ensure the repository name is correct and the files exist on Hugging Face Hub.")
138
+ ```