fazni commited on
Commit
45dd0ef
1 Parent(s): 130a0f0

changed the model

Browse files
Files changed (1) hide show
  1. Components/model_Responce.py +41 -17
Components/model_Responce.py CHANGED
@@ -1,9 +1,11 @@
 
1
  import pickle
2
  import joblib
3
  import numpy as np
4
  import tensorflow as tf
5
  from keras.utils import pad_sequences
6
  from keras.preprocessing.text import Tokenizer
 
7
 
8
  # Load the model from the pickle file
9
  # filename = 'F:/CVFilter/models/model_pk.pkl'
@@ -13,26 +15,48 @@ from keras.preprocessing.text import Tokenizer
13
  # Load the saved model
14
  # model = joblib.load('F:\CVFilter\models\model.joblib')
15
 
16
- model = tf.keras.models.load_model('models\model.h5')
17
 
18
- tokenfile = 'tokenized_words/tokenized_words.pkl'
19
- # Load the tokenized words from the pickle file
20
- with open(tokenfile, 'rb') as file:
21
- loaded_tokenized_words = pickle.load(file)
22
 
23
- max_review_length = 200
24
- tokenizer = Tokenizer(num_words=10000, #max no. of unique words to keep
25
- filters='!"#$%&()*+,-./:;<=>?@[\]^_`{|}~',
26
- lower=True #convert to lower case
27
- )
28
- tokenizer.fit_on_texts(loaded_tokenized_words)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  outcome_labels = ['Business Analyst', 'Cyber Security','Data Engineer','Data Science','DevOps','Machine Learning Engineer','Mobile App Developer','Network Engineer','Quality Assurance','Software Engineer']
31
 
32
  def model_prediction(text, model=model, tokenizer=tokenizer, labels=outcome_labels):
33
- seq = tokenizer.texts_to_sequences([text])
34
- padded = pad_sequences(seq, maxlen=max_review_length)
35
- pred = model.predict(padded)
36
- # print("Probability distribution: ", pred)
37
- # print("Field ")
38
- return labels[np.argmax(pred)]
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
  import pickle
3
  import joblib
4
  import numpy as np
5
  import tensorflow as tf
6
  from keras.utils import pad_sequences
7
  from keras.preprocessing.text import Tokenizer
8
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
9
 
10
  # Load the model from the pickle file
11
  # filename = 'F:/CVFilter/models/model_pk.pkl'
 
15
  # Load the saved model
16
  # model = joblib.load('F:\CVFilter\models\model.joblib')
17
 
 
18
 
19
+ # Load Local Model and Local tokenizer
20
+ # model = tf.keras.models.load_model('models\model.h5')
 
 
21
 
22
+ # tokenfile = 'tokenized_words/tokenized_words.pkl'
23
+ # # Load the tokenized words from the pickle file
24
+ # with open(tokenfile, 'rb') as file:
25
+ # loaded_tokenized_words = pickle.load(file)
26
+
27
+ # max_review_length = 200
28
+ # tokenizer = Tokenizer(num_words=10000, #max no. of unique words to keep
29
+ # filters='!"#$%&()*+,-./:;<=>?@[\]^_`{|}~',
30
+ # lower=True #convert to lower case
31
+ # )
32
+ # tokenizer.fit_on_texts(loaded_tokenized_words)
33
+
34
+
35
+ # Load Huggingface model and tokenizer
36
+ # Define the model name
37
+ model_name = "fazni/distilbert-base-uncased-career-path-prediction"
38
+
39
+ # Load the model
40
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
41
+
42
+ # Load the tokenizer
43
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
44
 
45
  outcome_labels = ['Business Analyst', 'Cyber Security','Data Engineer','Data Science','DevOps','Machine Learning Engineer','Mobile App Developer','Network Engineer','Quality Assurance','Software Engineer']
46
 
47
  def model_prediction(text, model=model, tokenizer=tokenizer, labels=outcome_labels):
48
+ # Local model
49
+ # seq = tokenizer.texts_to_sequences([text])
50
+ # padded = pad_sequences(seq, maxlen=max_review_length)
51
+ # pred = model.predict(padded)
52
+ # return labels[np.argmax(pred)]
53
+
54
+ # Hugging face model
55
+ # Tokenize the text
56
+ inputs = tokenizer(text, return_tensors="pt")
57
+ outputs = model(**inputs)
58
+
59
+ # Get the predicted class probabilities
60
+ probs = outputs.logits.softmax(dim=-1)
61
+
62
+ return labels[torch.argmax(probs)]