Transcription of 研究者流 コーディングの極意 - chokkan.org
1 19 (NLP2013) okazaki at @chokkanorg 1 C++ *NIX Windows .. 2 ..3 [Sutton 2012] 4 5 = [ 2012] : vs.
2 Vs 100 6 100 100 100 NLP 145 RTs, 227 favs, 744 Hatenabookmarks9 10 tail ( 6) importsysN = int( [1])val = -1lines = ()whileval != -N-1 (lines[val])val +=-1val val -= 1for 11 importsysimportrepattern = re. compile(ur'[^ 0-9 - a-zA-Z - - - - - ]+$')forline :line = (' n')form (unicode(line)) ('%s n' % (0))12 importsysimportrep = re. compile(u"[ ]+")forline :a = (unicode(line,'utf-8'))ifa:forb ina:printb13100 1.
3 2. 3. 4. 5. 6. 7. 141. 15 : 100 16 McIlroy UNIX [Salus+ 1994] 17 100 182. cat | mecab | grep $' t ' | cut -f1 | sort | uniq -c | sort -nr# # # # # 80 192. UNIX sort, cut, grep, make, .. cabocha, gnuplot, SQL, lucene.
4 Json, nltk, matplotlib, .. 203. Computers are good at following instructions, but not at reading your mind (Donald Knuth) 21 (1/4)def readiter(fi):S = []for line in fi:line = (' n')if (dict(zip (('w', 'pos', 'chunk'), (' '))))else:yieldSS = [] CoNLL 2000 22 (2/4)def readiter(fi):S = []for line in fi:line = (' n')if (dict(zip (('w', 'pos', 'chunk'), (' '))))else:yieldSS = []if __name__ == '__main__':importsysfor S in readiter( ):for token in S:sys.
5 ('%(w)s%(pos)s%(chunk)s n' % token)sys . (' n') readiter Rockwell NNP B-NPInternational NNP I-NPCorp. NNP I-NP's POS B-NPTulsa NNP I-NPunit NN I-NPsaid VBD B-VPRockwell NNP B-NPInternational NNP I-NPCorp. NNP I-NP's POS B-NPTulsa NNP I-NPunit NN I-NPsaid VBD B-VP 23 (3/4)def readiter(fi):S = []for line in fi:line = (' n')if (dict(zip (('w', 'pos', 'chunk'), (' '))))else:yieldSS = []def observation(v):# An initial uppercase ['iu' ] = v['w'][0].isupper() 24 (4/4)def readiter(fi):S = []for line in fi:line = (' n')if (dict(zip (('w', 'pos', 'chunk'), (' '))))else:yieldSS = []def observation(v):# An initial uppercase ['iu' ] = v['w'][0].
6 Isupper()if __name__ == '__main__':importsysfor S in readiter( ):for token in S:observation(token)sys . ('%(w)s%(pos)s%(iu)s%(chunk)s n' % token)sys . (' n') Rockwell NNP True B- NPInternational NNP True I-NPCorp. NNP True I-NP's POS False B-NPTulsa NNP True I-NPunit NN False I-NPsaid VBD False B-VP254. [Eslami2012]26 npclust|+-------bin|+-------data|+------ -work| || + |+-------result .bashrc 27 git, mercurial, subversion Makefile, Ant, 285.
7 29 Microsoft Excel, HTML gnuplot, matplotlib, Google Chart graphviz, Gephi, Microsoft Excel, HTML, brat google-code-prettify, Pygments HTML, JavaScript, CSS, .. 30 50 importsysimportmatplotlib; ( 'Agg') plty = []for line in :line = line .strip(' n')fields = line .split(' t') (float(fields[0]))y = sorted(y, reverse=True) (y, '.') ('Rank') ('Frequency') ("Zipf's law") (" ")31 69: importsysprint'graph G {'print' size="20,20";'for line in :line = line .strip(' n')fields = line .split(' t')sim = float(fields[0])if <= sim:length = 1 - simweight = simprint'%s--%s[length=%f, weight=%f];' % (fields[1],fields[2],length,weight)print '}'326.
8 Prototype before polishing. Get it working before you optimize it. [Raymond 2003] Programmer time is expensive; conserve it in preference to machine time. [Raymond 2003] Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. (Brian Kernighan) Make it work. Make it right. Make it fast. (Kent Beck) (Donald Knuth)336. Make it right Make it work Make it fast 347. 35 github 36 "Keep It Simple, Stupid!
9 " (KISS 37 Kenneth W. Church. Unix for Dredze, Hanna M. Wallach. 2012. How to be a Successful PhD Student (in Computer Science (in NLP/ML)). ~ M. Ali Eslami. 2012. Patterns for Research in Machine D. McIlroy, E. N. Pinson, B. A. Tague. 1978. UNIX Time-Sharing System: Forward. The Bell System Technical Journal, Vol. 57, Issue 6, pp. S. Raymond. 2003. The Art of UNIX Programming. H. Salus. 1994. A Quarter-Century of Unix. Sutton. 2012. Principles of Research . 2012.. Vol. 19, No. 1, pp.)