This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# calculating ideal recall@k | |
ideal_recall_at_k = np.minimum( | |
np.ones(len(ranking)), | |
np.array(list(range(1, len(ranking) + 1)))/ (ranking == 1).sum() | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# calculating ideal recall@k | |
ideal_recall_at_k = np.minimum( | |
np.ones(len(conf_df)), | |
np.array(list(range(1, len(conf_df["expected"]) + 1)))/ conf_df["expected"].to_list().count(1) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# calculating recall@k | |
for i in range(len(conf_df)): | |
recall_at_k.append( | |
conf_df.iloc[:i+1, :]["expected"].to_list().count(1) | |
/ conf_df["expected"].to_list().count(1) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conf_df = pd.DataFrame() | |
conf_df["conf"] = y_conf | |
conf_df["expected"] = y_true | |
conf_df.columns = ["conf", "expected"] | |
conf_df = conf_df.sort_values("conf", ascending=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@jit | |
def auc_recall_at_k_np_no_df_numba(y_true, y_conf): | |
""" | |
Experiment #4: | |
-------------- | |
Compute AUC under the Recall@k curve using numpy's | |
functions. We do away with the conf_df dataframe | |
as well. | |
Numba's jit decorator is also added for further |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def auc_recall_at_k_np_no_df(y_true, y_conf): | |
""" | |
Experiment #3: | |
-------------- | |
Compute AUC under the Recall@k curve using numpy's | |
functions. We do away with the conf_df dataframe | |
as well. | |
y_true: A numpy array of expected predictions | |
y_conf: A numpy array of the model's confidence |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def auc_recall_at_k_np(y_true, y_conf): | |
""" | |
Experiment #2: | |
-------------- | |
Compute AUC under the Recall@k curve using numpy's | |
functions. | |
y_true: A numpy array of expected predictions | |
y_conf: A numpy array of the model's confidence | |
scores for each datapoint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def auc_recall_at_k(y_true, y_conf): | |
""" | |
Compute AUC under the Recall@k curve. | |
y_true: A numpy array of expected predictions | |
y_conf: A numpy array of the model's confidence | |
scores for each datapoint | |
Returns: AUC-Recall@k (float) | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process(self, message: Message, **kwargs: Any) -> None: | |
""" | |
The driver method. Its executed after every user message. | |
""" | |
X = message.get_sparse_features(TEXT)[1].features.reshape(1, -1) | |
probs = self.clf.predict_proba(X).flatten() | |
intents = self.le.inverse_transform(self.clf.classes_) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "2.0" | |
nlu: | |
- intent: greet | |
examples: | | |
- hi | |
- hello | |
- intent: supply_contact_info | |
examples: | | |
- My name is [John](name). email's [john@email.com](email) |
NewerOlder