Skip to content

Instantly share code, notes, and snippets.

@thomashikaru
thomashikaru / conll_en_example.txt
Created July 2, 2022 22:10
example of english dependency parse data
# sent_id = answers-20111108084416AAoPgBv_ans-0020
# text = Everything about the place is magical and the people are mostly friendly.
1 Everything everything PRON NN Number=Sing 6 nsubj 6:nsubj _
2 about about ADP IN _ 4 case 4:case _
3 the the DET DT Definite=Def|PronType=Art 4 det 4:det _
4 place place NOUN NN Number=Sing 1 nmod 1:nmod _
5 is be AUX VBZ Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin 6 cop 6:cop _
6 magical magical ADJ JJ Degree=Pos 0 root 0:root _
7 and and CCONJ CC _ 12 cc 12:cc _
8 the the DET DT Definite=Def|PronType=Art 9 det 9:det _
import pygame
import numpy as np
import itertools
import sys
import networkx as nx
import collections
from pygame import gfxdraw
# Game constants
# sent_id = 1288710
# text = Возможно, это ощущение было еще сильнее, чем удовлетворение от самого успеха.
1 Возможно возможно ADV _ Degree=Pos 7 parataxis _ SpaceAfter=No
2 , , PUNCT _ _ 1 punct _ _
3 это этот DET _ Case=Nom|Gender=Neut|Number=Sing 4 amod _ _
4 ощущение ощущение NOUN _ Animacy=Inan|Case=Nom|Gender=Neut|Number=Sing 7 nsubj _ _
5 было быть AUX _ Aspect=Imp|Gender=Neut|Mood=Ind|Number=Sing|Tense=Past|VerbForm=Fin|Voice=Act 7 cop _ _
6 еще еще ADV _ Degree=Pos 7 advmod _ _
7 сильнее сильный ADJ _ Degree=Cmp 0 root _ SpaceAfter=No
8 , , PUNCT _ _ 7 punct _ _
from collections import defaultdict
d = defaultdict(int)
print(d["Alice"]) # prints 0
d["Bob"] += 1
print(d["Bob"]) # prints 1
d = defaultdict(list)
d["John"].append("eggs")
from collections import defaultdict
class BigramModel:
def train(self, training_set):
self.d = defaultdict(lambda: defaultdict(int))
for sent in training_set:
for w1, w2 in zip(sent[:-1], sent[1:]):
self.d[w1][w2] += 1
from collections import Counter
import glob
# get list of filenames matching a pattern using glob
filenames = glob.glob("path/to/many/files/*.txt")
# create empty counter object
counts = Counter()
# loop over files, create a counter for each, and merge into counts
# without formatter
dictionary = {"a":[1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1], "b":[9,8,7,6,5,4,3,2,1,2,3,4,5,6,7,8,9]}
list_of_items = [f"A: {a}, B: {b}, C: {c}" for a, b, c in itertools.product(range(0,100,2), range(0,100,3), range(0,100,4))]
# with formatter
dictionary = {
"a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1],
"b": [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9],
}
list_of_items = [
import argparse
import pandas as pd
if __name__ == "__main__":
# create argument parser and define arguments
parser = argparse.ArgumentParser()
parser.add_argument("--inputfile", default="inputfile.csv")
parser.add_argument("--num_rows", type=int, default=10)
parser.add_argument("--print_output", action="store_true")
import torch
import plotly.graph_objects as go
import numpy as np
# Batch Size, Input Neurons, Hidden Neurons, Output Neurons
N, D_in, H, D_out = 16, 1, 1024, 1
# Create random Tensors to hold inputs and outputs
x = torch.randn(N, D_in)
y = torch.randn(N, D_out)
import torch
import plotly.express as px
import pandas as pd
# Batch Size, Input Neurons, Hidden Neurons, Output Neurons
N, D_in, H, D_out = 128, 2, 1024, 1
# Create random Tensors to hold inputs and outputs
x = torch.rand(N, D_in)
y = torch.randint(0, 2, (N, D_out))