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 | |
from scipy.optimize import fmin_bfgs | |
def rosen(x): | |
return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:1])**2.0) | |
def rosen_der(x): | |
xm = x[1:-1] | |
xm_m1 = x[:-2] | |
xm_p1 = x[2:] |
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
#!/usr/bin/python | |
# crf.py (by Graham Neubig) | |
# This script trains conditional random fields (CRFs) | |
# stdin: A corpus of WORD_POS WORD_POS WORD_POS sentences | |
# stdout: Feature vectors for emission and transition properties | |
from collections import defaultdict | |
from math import log, exp | |
import sys |