Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andreped authored Apr 10, 2023
1 parent c0aaac2 commit c09178f
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 307 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pip install -r requirements.txt

Perform experiment by running the following lines:
```
cd cogito-nlp-workshop-spring-2020/
python train.py
```

Expand Down
21 changes: 21 additions & 0 deletions metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from keras import backend as K


def recall_m(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall


def precision_m(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision


def f1_m(y_true, y_pred):
precision = precision_m(y_true, y_pred)
recall = recall_m(y_true, y_pred)
return 2 * ((precision * recall) / (precision + recall + K.epsilon()))
21 changes: 21 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from keras.layers import Input, Dense, Dropout
from keras.models import Model


def get_model(num_feats, class_nbs):
x = Input(shape=(num_feats, ))
shared = Dense(64, activation="relu")(x) # x
sub1 = Dense(32, activation="relu")(shared)
#sub1 = Dropout(0.5)(sub1)

sub2 = Dense(32, activation="relu")(shared)
#sub2 = Dropout(0.5)(sub2)

sub3 = Dense(32, activation="relu")(shared)
#sub3 = Dropout(0.5)(sub3)

out1 = Dense(class_nbs[0], activation="softmax")(sub1)
out2 = Dense(class_nbs[1], activation="softmax")(sub2)
out3 = Dense(class_nbs[2], activation="softmax")(sub3)

model = Model(inputs=x, outputs=[out1, out2, out3])
6 changes: 0 additions & 6 deletions notes
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,3 @@ NLP:
- Main challenge, natural language is ambigeous and complex -> need to kind of guess a lot
- split sentence in sentences -> split on periods ex.
- Classify text if positive or negative -> IMDB dataset






Loading

0 comments on commit c09178f

Please sign in to comment.