Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix task 6 #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dlnlputils/recipe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def plot_recipe_statistics(correct_recipes, total_recipes=None):

def plot_confusion_matrix(y_true, y_pred, classes, normalize=False, title=None, cmap=plt.cm.Blues):

cm = confusion_matrix(y_true, y_pred, classes)
cm = confusion_matrix(y_true, y_pred, labels = classes)
if normalize:
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]

Expand Down
16 changes: 8 additions & 8 deletions task5_text_transformer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@
" is_training,\n",
" weights_dropout):\n",
" \"\"\"\n",
" queries - BatchSize x ValuesLen x HeadN x KeySize\n",
" queries - BatchSize x QueriesLen x HeadN x KeySize\n",
" keys - BatchSize x KeysLen x HeadN x KeySize\n",
" values - BatchSize x KeysLen x HeadN x ValueSize\n",
" keys_padding_mask - BatchSize x KeysLen\n",
Expand All @@ -821,12 +821,12 @@
" weights_dropout - float\n",
" \n",
" result - tuple of two:\n",
" - BatchSize x ValuesLen x HeadN x ValueSize - resulting features\n",
" - BatchSize x ValuesLen x KeysLen x HeadN - attention map\n",
" - BatchSize x QueriesLen x HeadN x ValueSize - resulting features\n",
" - BatchSize x QueriesLen x KeysLen x HeadN - attention map\n",
" \"\"\"\n",
"\n",
" # BatchSize x ValuesLen x KeysLen x HeadN\n",
" relevances = torch.einsum('bvhs,bkhs->bvkh', (queries, keys))\n",
" # BatchSize x QueriesLen x KeysLen x HeadN\n",
" relevances = torch.einsum('bqhs,bkhs->bqkh', (queries, keys))\n",
" \n",
" # замаскировать элементы, выходящие за длины последовательностей ключей\n",
" padding_mask_expanded = keys_padding_mask[:, None, :, None].expand_as(relevances)\n",
Expand All @@ -838,15 +838,15 @@
" normed_rels = F.softmax(relevances, dim=2) \n",
" normed_rels = F.dropout(normed_rels, weights_dropout, is_training)\n",
" \n",
" # BatchSize x ValuesLen x KeysLen x HeadN x 1\n",
" # BatchSize x QueriesLen x KeysLen x HeadN x 1\n",
" normed_rels_expanded = normed_rels.unsqueeze(-1)\n",
" \n",
" # BatchSize x 1 x KeysLen x HeadN x ValueSize\n",
" values_expanded = values.unsqueeze(1)\n",
" \n",
" # BatchSize x ValuesLen x KeysLen x HeadN x ValueSize\n",
" # BatchSize x QueriesLen x KeysLen x HeadN x ValueSize\n",
" weighted_values = normed_rels_expanded * values_expanded\n",
" result = weighted_values.sum(2) # BatchSize x ValuesLen x HeadN x ValueSize\n",
" result = weighted_values.sum(2) # BatchSize x QueriesLen x HeadN x ValueSize\n",
" \n",
" return result, normed_rels"
]
Expand Down
2 changes: 1 addition & 1 deletion task6_recipe_ner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
" \n",
" \n",
" if i % 500 == 0:\n",
" liveplot.update({'negative log likelihood loss': loss})\n",
" liveplot.update({'negative log likelihood loss': loss.detach()})\n",
" liveplot.draw()\n",
" \n",
" \n",
Expand Down