Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhers committed Jul 13, 2017
1 parent f1c0e78 commit f652395
Show file tree
Hide file tree
Showing 31 changed files with 91 additions and 86 deletions.
2 changes: 1 addition & 1 deletion scheme/constraint/amr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from util.amr import *
from scheme.util.amr import *


class Constraints(constraints.Constraints):
Expand Down
5 changes: 2 additions & 3 deletions scheme/conversion/amr.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from collections import defaultdict, namedtuple, OrderedDict

import penman
from collections import defaultdict, namedtuple, OrderedDict
from ucca import layer0, layer1, convert

from util.amr import *
from scheme.util.amr import *

DELETE_PATTERN = re.compile("\\\\|(?<=(?<!<)<)[^<>]+(?=>(?!>))") # Delete text inside single angle brackets

Expand Down
7 changes: 4 additions & 3 deletions scheme/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import argparse
import glob
import os
import re
import sys

from conversion.amr import CONVERTERS
import os
import re
from ucca.convert import split2sentences
from ucca.ioutil import passage2file, file2passage

from scheme.conversion.amr import CONVERTERS

desc = """Parses files in the specified format, and writes as the specified format.
Each passage is written to the file: <outdir>/<prefix><passage_id>.<extension> """

Expand Down
9 changes: 5 additions & 4 deletions scheme/convert_and_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import argparse
import glob
import os
import sys

from conversion.amr import from_amr, to_amr
from evaluation.amr import evaluate, Scores
from tupa.config import VAction
import os
from ucca.ioutil import passage2file

from scheme.conversion.amr import from_amr, to_amr
from scheme.evaluation.amr import evaluate, Scores
from tupa.config import VAction

desc = """Parses files in AMR format, converts to UCCA standard format,
converts back to the original format and evaluates using smatch.
"""
Expand Down
2 changes: 1 addition & 1 deletion scheme/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import argparse

from evaluation.amr import evaluate
from scheme.evaluation.amr import evaluate
from tupa.config import VAction

desc = """Parses files in AMR format, and evaluates using smatch.
Expand Down
2 changes: 1 addition & 1 deletion scheme/evaluation/amr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from util.amr import *
from scheme.util.amr import *

sys.path.insert(0, os.path.dirname(importlib.util.find_spec("smatch.smatch").origin)) # to find amr.py from smatch
from smatch import smatch
Expand Down
5 changes: 2 additions & 3 deletions scheme/split.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env python3
import argparse
import sys

import glob
import sys

from util.amr import *
from scheme.util.amr import *

desc = """Split AMRs to separate files (important for shuffling before training the parser)"""

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ def run(self):
"src": os.path.join("scheme", "amr", "src"),
"smatch": os.path.join("scheme", "smatch"),
},
package_data={"src": ["amr.peg"], "util": ["resources/*.txt"]},
package_data={"src": ["amr.peg"], "scheme.util": ["resources/*.txt"]},
cmdclass={"install": install},
)
5 changes: 3 additions & 2 deletions tests/test_amr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import unittest

from conversion.amr import from_amr, to_amr
from evaluation.amr import evaluate
from ucca.convert import split2sentences

from scheme.conversion.amr import from_amr, to_amr
from scheme.evaluation.amr import evaluate


class ConversionTests(unittest.TestCase):
"""Tests conversion module correctness and API."""
Expand Down
5 changes: 3 additions & 2 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import unittest

from states.state import State
from ucca import convert, evaluation, ioutil

from tupa.action import Actions
from tupa.config import Config, SPARSE, MLP_NN, BILSTM_NN, NOOP
from tupa.oracle import Oracle
from tupa.parse import Parser
from ucca import convert, evaluation, ioutil
from tupa.states.state import State

NUM_PASSAGES = 2

Expand Down
2 changes: 1 addition & 1 deletion tupa/action.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tupa.config import Config, COMPOUND
from .config import Config, COMPOUND


class Action(object):
Expand Down
2 changes: 1 addition & 1 deletion tupa/classifiers/linear/perceptron.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time

from classifiers.classifier import Classifier, ClassifierProperty
from tupa.classifiers.classifier import Classifier, ClassifierProperty


class Perceptron(Classifier):
Expand Down
5 changes: 2 additions & 3 deletions tupa/classifiers/linear/sparse_perceptron.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from collections import defaultdict

import numpy as np
from collections import defaultdict

from linear.perceptron import Perceptron
from tupa.config import Config, SPARSE
from .perceptron import Perceptron


class FeatureWeights(object):
Expand Down
6 changes: 3 additions & 3 deletions tupa/classifiers/nn/bilstm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import dynet as dy

from classifiers.classifier import ClassifierProperty
from features.feature_params import MISSING_VALUE
from nn.neural_network import NeuralNetwork
from tupa.classifiers.classifier import ClassifierProperty
from tupa.config import Config, BILSTM_NN
from tupa.features.feature_params import MISSING_VALUE
from .neural_network import NeuralNetwork


class BiLSTM(NeuralNetwork):
Expand Down
2 changes: 1 addition & 1 deletion tupa/classifiers/nn/feedforward.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from nn.neural_network import NeuralNetwork
from tupa.config import MLP_NN
from .neural_network import NeuralNetwork


class MLP(NeuralNetwork):
Expand Down
10 changes: 5 additions & 5 deletions tupa/classifiers/nn/neural_network.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
import sys
import time
from collections import OrderedDict

import dynet as dy
import numpy as np
import os
from collections import OrderedDict

from classifiers.classifier import Classifier
from classifiers.classifier import ClassifierProperty
from features.feature_params import MISSING_VALUE
from tupa.classifiers.classifier import Classifier
from tupa.classifiers.classifier import ClassifierProperty
from tupa.config import Config
from tupa.features.feature_params import MISSING_VALUE

TRAINERS = {
"sgd": (dy.SimpleSGDTrainer, "e0"),
Expand Down
2 changes: 1 addition & 1 deletion tupa/classifiers/noop.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from classifiers.classifier import Classifier
from tupa.config import NOOP
from .classifier import Classifier


class NoOp(Classifier):
Expand Down
8 changes: 4 additions & 4 deletions tupa/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import sys

import numpy as np
from conversion.amr import CONVERTERS
from ucca import evaluation, constructions

from tupa import constraints
from scheme.conversion.amr import CONVERTERS
from . import constraints


class Singleton(type):
Expand Down Expand Up @@ -181,8 +181,8 @@ def __init__(self, *args):
self.args.max_node_labels = 1000
self.args.max_action_labels = max(self.args.max_action_labels, 600)
self.args.max_edge_labels = max(self.args.max_edge_labels, 500)
from evaluation.amr import evaluate, Scores, LABEL_ATTRIB, UNKNOWN_LABEL
from constraint.amr import Constraints
from scheme.evaluation.amr import evaluate, Scores, LABEL_ATTRIB, UNKNOWN_LABEL
from scheme.constraint.amr import Constraints
self.evaluate, self.Scores = evaluate, Scores
self.args.node_label_attrib = LABEL_ATTRIB
self.args.unknown_label = UNKNOWN_LABEL
Expand Down
4 changes: 2 additions & 2 deletions tupa/features/dense_features.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from features.feature_extractor import FeatureExtractor
from features.feature_params import MISSING_VALUE
from .feature_extractor import FeatureExtractor
from .feature_params import MISSING_VALUE

NON_NUMERIC_FEATURE_SUFFIXES = "wtdenpAT"
FEATURE_TEMPLATES = (
Expand Down
2 changes: 1 addition & 1 deletion tupa/features/empty_features.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from features.feature_extractor import FeatureExtractor
from .feature_extractor import FeatureExtractor


class EmptyFeatureExtractor(FeatureExtractor):
Expand Down
6 changes: 3 additions & 3 deletions tupa/features/enumerator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import numpy as np

from features.feature_extractor_wrapper import FeatureExtractorWrapper
from features.feature_params import MISSING_VALUE
from features.feature_params import NumericFeatureParameters
from tupa.model_util import DropoutDict
from .feature_extractor_wrapper import FeatureExtractorWrapper
from .feature_params import MISSING_VALUE
from .feature_params import NumericFeatureParameters


class FeatureEnumerator(FeatureExtractorWrapper):
Expand Down
7 changes: 4 additions & 3 deletions tupa/features/feature_extractor_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from features.feature_extractor import FeatureExtractor
from features.feature_params import copy_params, NumericFeatureParameters
from tupa.model_util import load_dict, save_dict, UnknownDict
from ucca.textutil import get_word_vectors

from tupa.model_util import load_dict, save_dict, UnknownDict
from .feature_extractor import FeatureExtractor
from .feature_params import copy_params, NumericFeatureParameters


class FeatureExtractorWrapper(FeatureExtractor):
def __init__(self, feature_extractor, params):
Expand Down
2 changes: 1 addition & 1 deletion tupa/features/indexer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from features.feature_extractor_wrapper import FeatureExtractorWrapper
from .feature_extractor_wrapper import FeatureExtractorWrapper

INDEXED_FEATURES = "W", "w", "t", "d", "T" # external word embeddings, learned word embeddings, POS tags, dep rels, entity type

Expand Down
2 changes: 1 addition & 1 deletion tupa/features/sparse_features.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from features.feature_extractor import FeatureExtractor
from .feature_extractor import FeatureExtractor

FEATURE_TEMPLATES = (
# unigrams (Zhang and Clark 2009):
Expand Down
28 changes: 14 additions & 14 deletions tupa/model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from features.enumerator import FeatureEnumerator
from features.feature_params import FeatureParameters
from features.indexer import FeatureIndexer
from tupa.action import Actions
from tupa.config import Config, SPARSE, MLP_NN, BILSTM_NN, NOOP
from tupa.model_util import UnknownDict
from .action import Actions
from .config import Config, SPARSE, MLP_NN, BILSTM_NN, NOOP
from .features.enumerator import FeatureEnumerator
from .features.feature_params import FeatureParameters
from .features.indexer import FeatureIndexer
from .model_util import UnknownDict

ACTION_AXIS = 0
LABEL_AXIS = 1
Expand Down Expand Up @@ -48,23 +48,23 @@ def __init__(self, model_type, filename, feature_extractor=None, model=None):
max_values.append(Config().args.max_node_labels)

if model_type == SPARSE:
from features.sparse_features import SparseFeatureExtractor
from linear.sparse_perceptron import SparsePerceptron
from .features.sparse_features import SparseFeatureExtractor
from .classifiers.linear.sparse_perceptron import SparsePerceptron
self.feature_extractor = SparseFeatureExtractor()
self.model = SparsePerceptron(filename, values)
elif model_type == MLP_NN:
from nn.feedforward import MLP
from features.dense_features import DenseFeatureExtractor
from .classifiers.nn.feedforward import MLP
from .features.dense_features import DenseFeatureExtractor
self.feature_extractor = FeatureEnumerator(DenseFeatureExtractor(), self.feature_params)
self.model = MLP(filename, values, self.feature_extractor.params, max_num_labels=max_values)
elif model_type == BILSTM_NN:
from nn.bilstm import BiLSTM
from features.dense_features import DenseFeatureExtractor
from .classifiers.nn.bilstm import BiLSTM
from .features.dense_features import DenseFeatureExtractor
self.feature_extractor = FeatureIndexer(FeatureEnumerator(DenseFeatureExtractor(), self.feature_params))
self.model = BiLSTM(filename, values, self.feature_extractor.params, max_num_labels=max_values)
elif model_type == NOOP:
from features.empty_features import EmptyFeatureExtractor
from classifiers.noop import NoOp
from .features.empty_features import EmptyFeatureExtractor
from .classifiers.noop import NoOp
self.feature_extractor = EmptyFeatureExtractor()
self.model = NoOp(filename, values)
else:
Expand Down
6 changes: 3 additions & 3 deletions tupa/model_util.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import pickle
import pprint as pp
import sys
import time
from collections import OrderedDict, Counter

import numpy as np
import os
from collections import OrderedDict, Counter

from features.feature_params import UNKNOWN_VALUE
from .features.feature_params import UNKNOWN_VALUE


class DefaultOrderedDict(OrderedDict):
Expand Down
7 changes: 4 additions & 3 deletions tupa/oracle.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from states.state import InvalidActionError
from tupa.action import Actions
from tupa.config import Config, COMPOUND
from ucca import layer1

from .action import Actions
from .config import Config, COMPOUND
from .states.state import InvalidActionError

# Constants for readability, used by Oracle.action
RIGHT = PARENT = NODE = 0
LEFT = CHILD = EDGE = 1
Expand Down
13 changes: 7 additions & 6 deletions tupa/parse.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import os
import time
from collections import defaultdict
from enum import Enum

from classifiers.classifier import ClassifierProperty
from states.state import State
import os
from collections import defaultdict
from ucca import diffutil, ioutil, textutil, layer1
from ucca.convert import FROM_FORMAT, TO_FORMAT, from_text, to_text

from tupa.classifiers.classifier import ClassifierProperty
from tupa.config import Config
from tupa.model import Model, ACTION_AXIS, LABEL_AXIS
from tupa.oracle import Oracle
from ucca import diffutil, ioutil, textutil, layer1
from ucca.convert import FROM_FORMAT, TO_FORMAT, from_text, to_text
from tupa.states.state import State


class ParserException(Exception):
Expand Down
4 changes: 2 additions & 2 deletions tupa/states/node.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from collections import deque
from operator import attrgetter

from tupa.config import Config
from ucca import core, layer0
from ucca.layer1 import EdgeTags

from tupa.config import Config


class Node(object):
"""
Expand Down
Loading

0 comments on commit f652395

Please sign in to comment.