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
| """Information Retrieval metrics | |
| Useful Resources: | |
| http://www.cs.utexas.edu/~mooney/ir-course/slides/Evaluation.ppt | |
| http://www.nii.ac.jp/TechReports/05-014E.pdf | |
| http://www.stanford.edu/class/cs276/handouts/EvaluationNew-handout-6-per.pdf | |
| http://hal.archives-ouvertes.fr/docs/00/72/67/60/PDF/07-busa-fekete.pdf | |
| Learning to Rank for Information Retrieval (Tie-Yan Liu) | |
| """ | |
| import numpy as np |
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
| import os | |
| import sys | |
| import json | |
| import pickle | |
| import numpy as np | |
| import pandas as pd | |
| import matplotlib | |
| matplotlib.rcParams['pdf.fonttype'] = 42 | |
| matplotlib.rcParams['ps.fonttype'] = 42 | |
| import matplotlib.pyplot as plt |
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
| from __future__ import absolute_import | |
| from __future__ import division | |
| from __future__ import print_function | |
| import sys | |
| from absl import app | |
| from absl import flags | |
| from absl import logging |
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
| class TableCell(object): | |
| bg_colour = None | |
| def __init__(self, value, header=False, bg_colour=None, text_colour=None): | |
| self.value = value | |
| self.header = header | |
| self.bg_colour = bg_colour | |
| self.text_colour = text_colour | |
| def _make_css(self): |
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
| class MultiheadAttention(nn.Module): | |
| """Multi-headed attention. | |
| See "Attention Is All You Need" for more details. | |
| """ | |
| def __init__(self, embed_dim, num_heads, dropout=0., bias=True): | |
| super().__init__() | |
| self.embed_dim = embed_dim | |
| self.num_heads = num_heads | |
| self.dropout = dropout | |
| self.head_dim = embed_dim // num_heads |
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
| class SinusoidalPositionalEmbedding(nn.Module): | |
| """This module produces sinusoidal positional embeddings of any length. | |
| Padding symbols are ignored, but it is necessary to specify whether padding | |
| is added on the left side (left_pad=True) or right side (left_pad=False). | |
| """ | |
| def __init__(self, embedding_dim, padding_idx, left_pad, init_size=1024): | |
| super().__init__() | |
| self.embedding_dim = embedding_dim | |
| self.padding_idx = padding_idx |
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 make_positions(tensor, padding_idx, left_pad): | |
| """Replace non-padding symbols with their position numbers. | |
| Position numbers begin at padding_idx+1. | |
| Padding symbols are ignored, but it is necessary to specify whether padding | |
| is added on the left side (left_pad=True) or right side (left_pad=False). | |
| """ | |
| max_pos = padding_idx + 1 + tensor.size(1) | |
| if not hasattr(make_positions, 'range_buf'): | |
| make_positions.range_buf = tensor.new() | |
| make_positions.range_buf = make_positions.range_buf.type_as(tensor) |
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
| class LayerNorm(nn.Module): | |
| def __init__(self, features, eps=1e-6): | |
| super().__init__() | |
| self.gamma = nn.Parameter(torch.ones(features)) | |
| self.beta = nn.Parameter(torch.zeros(features)) | |
| self.eps = eps | |
| def forward(self, x): | |
| mean = x.mean(-1, keepdim=True) |
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
| m = nn.Conv1d(200, 10, 2) # in-channels = 200, out-channels = 10 | |
| input = Variable(torch.randn(10, 200, 5)) # 200 = embedding dim, 5 = seq length | |
| feature_maps = m(input) | |
| print(feature_maps.size()) # feature_maps size = 10,10,4 |
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
| <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js"></script> | |
| <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> | |
| <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
| <!-- 可选的 Bootstrap 主题文件(一般不用引入) --> | |
| <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> | |
| <!-- 最新的 Bootstrap 核心 JavaScript 文件 --> | |
| <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> |
NewerOlder