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 torch | |
| import lineflow as lf | |
| class Dictionary(object): | |
| def __init__(self): | |
| self.word2idx = {} | |
| self.idx2word = [] | |
| def add_word(self, word): |
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
| this is the first line . | |
| this is the second line . | |
| this is the third line . |
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 collections import deque | |
| INF = float('inf') | |
| def bfs(graph, s): | |
| d = {v: INF for v in graph} | |
| d[s] = 0 | |
| pi = {s: None} | |
| queue = deque([s]) | |
| while queue: |
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
| INF = float('inf') | |
| def bellman_ford(graph, weights, s): | |
| d = {v: INF for v in graph} | |
| d[s] = 0 | |
| pi = {s: None} | |
| edges = [(u, v) for u, vs in graph.items() for v in vs] | |
| for _ in range(len(graph) - 1): | |
| for (u, v) in edges: | |
| d_temp = d[u] + weights[u, v] |
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
| INF = float('inf') | |
| def dag_shortest_path(graph, weights, torder, s): | |
| d = {v: INF for v in graph} | |
| d[s] = 0 | |
| pi = {s: None} | |
| for u in torder: | |
| for v in graph[u]: | |
| d_temp = d[u] + weights[u, v] | |
| if d_temp < d[v]: |
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 heapq | |
| INF = float('inf') | |
| def dijkstra(graph, weights, s): | |
| d = {v: INF for v in graph} | |
| d[s] = 0 | |
| pi = {s: None} | |
| queue = [] | |
| heapq.heappush(queue, (0, s)) |
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
| $latex = 'platex'; | |
| $bibtex = 'pbibtex'; | |
| $dvipdf = 'dvipdfmx %O -o %D %S'; | |
| $makeindex = 'mendex %O -o %D %S'; | |
| $pdf_mode = 3; | |
| $ENV{TZ} = 'Asia/Tokyo'; | |
| $ENV{OPENTYPEFONTS} = '/usr/share/fonts//:'; | |
| $ENV{TTFONTS} = '/usr/share/fonts//:'; |
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
| ls -t * | xargs -I{} file {} | grep "PNG image data" | cut -d ":" -f 1 | parallel -j 8 convert "{}" -colorspace sRGB -type truecolor "target/{.}.jpg" |
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 numpy as np | |
| def batch_normalization(x, gamma, beta, eps=2e-5): | |
| mean = x.mean(axis=0) | |
| var = x.var(axis=0) | |
| x_hat = (x - mean) / np.sqrt(var + eps) | |
| return gamma * x_hat + beta | |
| def layer_normalization(x, gamma, beta, eps=2e-5): | |
| mean = x.mean(axis=1)[:, np.newaxis] |
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 replace_chars(text): | |
| chars = ",.?!:;" | |
| for c in chars: | |
| if c in text: | |
| text = text.replace(c, '') | |
| return text |
NewerOlder