chap0lin commited on
Commit
5e8712d
1 Parent(s): 1799b38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -1,15 +1,29 @@
1
  import gradio as gr
2
  from gensim.models import Word2Vec
 
3
  import keras
4
  from keras.utils.data_utils import pad_sequences
5
  import requests
6
  import shutil
7
  import requests
8
 
9
- def get_model(filename, url):
10
- response = requests.get(url, stream=True)
11
- with open(filename, 'wb') as fin:
12
- shutil.copyfileobj(response.raw, fin)
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # get_model("word2vec_xp8.model", "https://github.com/chap0lin/PPF-MCTI/blob/master/Meta10/pesos/word2vec/word2vec_xp8.model?raw=true")
15
  reloaded_w2v_model = Word2Vec.load('word2vec_xp8.model')
 
1
  import gradio as gr
2
  from gensim.models import Word2Vec
3
+ from gensim.models.callbacks import CallbackAny2Vec
4
  import keras
5
  from keras.utils.data_utils import pad_sequences
6
  import requests
7
  import shutil
8
  import requests
9
 
10
+ #initialise callback class
11
+ class callback(CallbackAny2Vec):
12
+ """
13
+ Print the loss value after each epoch
14
+ """
15
+ def __init__(self):
16
+ self.epoch = 0
17
+ #gensim loss is cumulative, so we record previous values to print
18
+ self.loss_previous_step = 0
19
+
20
+ def on_epoch_end(self, model):
21
+ loss = model.get_latest_training_loss()
22
+ if self.epoch % 100 == 0:
23
+ print('Loss after epoch {}: {}'.format(self.epoch, loss-self.loss_previous_step))
24
+
25
+ self.epoch+= 1
26
+ self.loss_previous_step = loss
27
 
28
  # get_model("word2vec_xp8.model", "https://github.com/chap0lin/PPF-MCTI/blob/master/Meta10/pesos/word2vec/word2vec_xp8.model?raw=true")
29
  reloaded_w2v_model = Word2Vec.load('word2vec_xp8.model')