Commit 6ac8a59c by Steven Bird

cleaned up import statements

parent b0aff2ab
...@@ -8,16 +8,16 @@ ...@@ -8,16 +8,16 @@
import tempfile import tempfile
import pickle import pickle
import os
import copy from os import remove
import operator from copy import deepcopy
from nltk.parse.api import ParserI from operator import itemgetter
import scipy.sparse as sparse from scipy import sparse
import numpy as np from numpy import array
from sklearn.datasets import load_svmlight_file from sklearn.datasets import load_svmlight_file
from sklearn import svm from sklearn import svm
from nltk.parse import DependencyGraph
from evaluate import DependencyEvaluator from nltk.parse import ParserI, DependencyGraph, DependencyEvaluator
class Configuration(object): class Configuration(object):
...@@ -522,7 +522,7 @@ class TransitionParser(ParserI): ...@@ -522,7 +522,7 @@ class TransitionParser(ParserI):
# Save the model to file name (as pickle) # Save the model to file name (as pickle)
pickle.dump(model, open(modelfile, 'wb')) pickle.dump(model, open(modelfile, 'wb'))
finally: finally:
os.remove(input_file.name) remove(input_file.name)
def parse(self, depgraphs, modelFile): def parse(self, depgraphs, modelFile):
""" """
...@@ -549,9 +549,9 @@ class TransitionParser(ParserI): ...@@ -549,9 +549,9 @@ class TransitionParser(ParserI):
col.append(self._dictionary[feature]) col.append(self._dictionary[feature])
row.append(0) row.append(0)
data.append(1.0) data.append(1.0)
np_col = np.array(sorted(col)) # NB : index must be sorted np_col = array(sorted(col)) # NB : index must be sorted
np_row = np.array(row) np_row = array(row)
np_data = np.array(data) np_data = array(data)
x_test = sparse.csr_matrix((np_data, (np_row, np_col)), shape=(1, len(self._dictionary))) x_test = sparse.csr_matrix((np_data, (np_row, np_col)), shape=(1, len(self._dictionary)))
...@@ -570,7 +570,7 @@ class TransitionParser(ParserI): ...@@ -570,7 +570,7 @@ class TransitionParser(ParserI):
# votes[j] +=1 # votes[j] +=1
# k +=1 # k +=1
# Sort votes according to the values # Sort votes according to the values
#sorted_votes = sorted(votes.items(), key=operator.itemgetter(1), reverse=True) #sorted_votes = sorted(votes.items(), key=itemgetter(1), reverse=True)
# We will use predict_proba instead of decision_function # We will use predict_proba instead of decision_function
prob_dict = {} prob_dict = {}
...@@ -579,7 +579,7 @@ class TransitionParser(ParserI): ...@@ -579,7 +579,7 @@ class TransitionParser(ParserI):
prob_dict[i] = pred_prob[i] prob_dict[i] = pred_prob[i]
sorted_Prob = sorted( sorted_Prob = sorted(
prob_dict.items(), prob_dict.items(),
key=operator.itemgetter(1), key=itemgetter(1),
reverse=True) reverse=True)
# Note that SHIFT is always a valid operation # Note that SHIFT is always a valid operation
...@@ -609,7 +609,7 @@ class TransitionParser(ParserI): ...@@ -609,7 +609,7 @@ class TransitionParser(ParserI):
# Finish with operations build the dependency graph from Conf.arcs # Finish with operations build the dependency graph from Conf.arcs
new_depgraph = copy.deepcopy(depgraph) new_depgraph = deepcopy(depgraph)
for key in new_depgraph.nodes: for key in new_depgraph.nodes:
node = new_depgraph.nodes[key] node = new_depgraph.nodes[key]
node['rel'] = '' node['rel'] = ''
...@@ -727,7 +727,7 @@ def demo(): ...@@ -727,7 +727,7 @@ def demo():
Number of training examples : 1 Number of training examples : 1
Number of valid (projective) examples : 1 Number of valid (projective) examples : 1
... ...
>>> os.remove(input_file.name) >>> remove(input_file.name)
B. Check the ARC-EAGER training B. Check the ARC-EAGER training
...@@ -743,7 +743,7 @@ def demo(): ...@@ -743,7 +743,7 @@ def demo():
Number of valid (projective) examples : 1 Number of valid (projective) examples : 1
... ...
>>> os.remove(input_file.name) >>> remove(input_file.name)
###################### Check The Parsing Function ######################## ###################### Check The Parsing Function ########################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment