Spaces:
Sleeping
Sleeping
Fix output activation is none error
Browse files- chatbot_constructor.py +5 -10
chatbot_constructor.py
CHANGED
|
@@ -14,14 +14,6 @@ import keras
|
|
| 14 |
|
| 15 |
os.mkdir("cache")
|
| 16 |
|
| 17 |
-
class ValueConstraint(Constraint):
|
| 18 |
-
def __init__(self, min_value: float = -1, max_value: float = 1):
|
| 19 |
-
self.min_value = min_value
|
| 20 |
-
self.max_value = max_value
|
| 21 |
-
|
| 22 |
-
def __call__(self, w):
|
| 23 |
-
return K.clip(w, self.min_value, self.max_value)
|
| 24 |
-
|
| 25 |
def todset(text: str):
|
| 26 |
lines = [x.rstrip("\n").lower().split("→") for x in text.split("\n")]
|
| 27 |
lines = [(x[0].replace("\\n", "\n"), x[1].replace("\\n", "\n")) for x in lines]
|
|
@@ -79,7 +71,7 @@ def train(message: str = "", regularization: float = 0.0001, dropout: float = 0.
|
|
| 79 |
concat1_layer = Concatenate()([flatten_layer, attn_flatten_layer, conv1_flatten_layer, conv2_flatten_layer, conv3_flatten_layer])
|
| 80 |
dropout2_layer = Dropout(dropout)(concat1_layer)
|
| 81 |
dense1_layer = Dense(1024, activation="linear", kernel_regularizer=L1(regularization))(dropout2_layer)
|
| 82 |
-
prelu1_layer = PReLU(
|
| 83 |
dropout3_layer = Dropout(dropout)(prelu1_layer)
|
| 84 |
dense2_layer = Dense(512, activation="relu", kernel_regularizer=L1(regularization))(dropout3_layer)
|
| 85 |
dropout4_layer = Dropout(dropout)(dense2_layer)
|
|
@@ -87,7 +79,10 @@ def train(message: str = "", regularization: float = 0.0001, dropout: float = 0.
|
|
| 87 |
dropout5_layer = Dropout(dropout)(dense3_layer)
|
| 88 |
dense4_layer = Dense(256, activation="relu", kernel_regularizer=L1(regularization))(dropout5_layer)
|
| 89 |
concat2_layer = Concatenate()([dense4_layer, prelu1_layer, attn_flatten_layer, conv1_flatten_layer])
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
model = Model(inputs=input_layer, outputs=dense4_layer)
|
| 92 |
|
| 93 |
X = []
|
|
|
|
| 14 |
|
| 15 |
os.mkdir("cache")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def todset(text: str):
|
| 18 |
lines = [x.rstrip("\n").lower().split("→") for x in text.split("\n")]
|
| 19 |
lines = [(x[0].replace("\\n", "\n"), x[1].replace("\\n", "\n")) for x in lines]
|
|
|
|
| 71 |
concat1_layer = Concatenate()([flatten_layer, attn_flatten_layer, conv1_flatten_layer, conv2_flatten_layer, conv3_flatten_layer])
|
| 72 |
dropout2_layer = Dropout(dropout)(concat1_layer)
|
| 73 |
dense1_layer = Dense(1024, activation="linear", kernel_regularizer=L1(regularization))(dropout2_layer)
|
| 74 |
+
prelu1_layer = PReLU()(dense1_layer)
|
| 75 |
dropout3_layer = Dropout(dropout)(prelu1_layer)
|
| 76 |
dense2_layer = Dense(512, activation="relu", kernel_regularizer=L1(regularization))(dropout3_layer)
|
| 77 |
dropout4_layer = Dropout(dropout)(dense2_layer)
|
|
|
|
| 79 |
dropout5_layer = Dropout(dropout)(dense3_layer)
|
| 80 |
dense4_layer = Dense(256, activation="relu", kernel_regularizer=L1(regularization))(dropout5_layer)
|
| 81 |
concat2_layer = Concatenate()([dense4_layer, prelu1_layer, attn_flatten_layer, conv1_flatten_layer])
|
| 82 |
+
if end_activation is not None:
|
| 83 |
+
dense4_layer = Dense(resps_len, activation=end_activation, kernel_regularizer=L1(regularization))(concat2_layer)
|
| 84 |
+
else:
|
| 85 |
+
dense4_layer = Dense(resps_len, activation="softmax", kernel_regularizer=L1(regularization))(concat2_layer)
|
| 86 |
model = Model(inputs=input_layer, outputs=dense4_layer)
|
| 87 |
|
| 88 |
X = []
|