Skip to content

Instantly share code, notes, and snippets.

View Polaris000's full-sized avatar

Aniruddha Karajgi Polaris000

View GitHub Profile
# 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()
)
# 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)
)
# 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)
)
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)
@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
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
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
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)
"""
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_)
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)