mirror of
https://github.com/wassname/Castor.git
synced 2026-09-09 11:13:20 +08:00
Kim's sentence classification model: Upgrade to Python 3 (#36)
Kim's sentence classification model: Upgrade to Python 3, per issue #31
This commit is contained in:
@@ -8,7 +8,7 @@ from __future__ import print_function
|
||||
import os
|
||||
import argparse
|
||||
|
||||
from ConfigParser import SafeConfigParser
|
||||
from configparser import SafeConfigParser
|
||||
|
||||
|
||||
class Configurable(object):
|
||||
@@ -37,7 +37,7 @@ class Configurable(object):
|
||||
config_file = kwargs.pop("config_file", "")
|
||||
config.read(config_file)
|
||||
# Override the config setting if the (k,v) specified in command line
|
||||
for option, value in kwargs.iteritems():
|
||||
for option, value in kwargs.items():
|
||||
assigned = False
|
||||
for section in config.sections():
|
||||
if option in config.options(section):
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ class Dataset(Configurable):
|
||||
super(Dataset, self).__init__(*args, **kwargs)
|
||||
self._train = (filename == self.train_file)
|
||||
self.vocabs = vocabs
|
||||
self.buckets = [Bucket(self._config, name='Sents-%d' % i) for i in xrange(self.n_bkts)]
|
||||
self.buckets = [Bucket(self._config, name='Sents-%d' % i) for i in range(self.n_bkts)]
|
||||
self.id2position = []
|
||||
self.len2bkts = {}
|
||||
self.vocabs = vocabs
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
from kmeans import KMeans
|
||||
from utils import clean_str, clean_str_sst
|
||||
from etc.kmeans import KMeans
|
||||
from etc.utils import clean_str, clean_str_sst
|
||||
@@ -86,7 +86,7 @@ class KMeans(object):
|
||||
def recenter(self):
|
||||
""""""
|
||||
|
||||
for split_idx in xrange(len(self._splits)):
|
||||
for split_idx in range(len(self._splits)):
|
||||
split = self._splits[split_idx]
|
||||
len_idx = self._split2len_idx[split]
|
||||
if split == self._splits[-1]:
|
||||
@@ -173,7 +173,7 @@ if __name__ == '__main__':
|
||||
""""""
|
||||
|
||||
len_cntr = Counter()
|
||||
for i in xrange(10000):
|
||||
for i in range(10000):
|
||||
len_cntr[1 + int(10 ** (1 + np.random.randn()))] += 1
|
||||
print(len_cntr)
|
||||
kmeans = KMeans(10, len_cntr)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ if __name__=='__main__':
|
||||
args, extra_args = argparser.parse_known_args()
|
||||
# args.train = True/False ...
|
||||
# extra_args['--some': "xxxx"]
|
||||
cargs = {k: v for (k, v) in vars(Configurable.argparser.parse_args(extra_args)).iteritems() if v is not None}
|
||||
cargs = {k: v for (k, v) in vars(Configurable.argparser.parse_args(extra_args)).items() if v is not None}
|
||||
|
||||
if 'model_type' not in cargs:
|
||||
print("You need to specify the model_type")
|
||||
|
||||
@@ -1 +1 @@
|
||||
from cnnText import *
|
||||
from model.cnnText import *
|
||||
@@ -1 +1 @@
|
||||
from cnntext import CNNText
|
||||
from model.cnnText.cnntext import CNNText
|
||||
@@ -6,7 +6,6 @@ import torch.nn as nn
|
||||
|
||||
import torch.nn.functional as F
|
||||
|
||||
from configurable import Configurable
|
||||
|
||||
class CNNText(nn.Module):
|
||||
"""
|
||||
|
||||
@@ -1 +1 @@
|
||||
from cnnTextNetwork import cnnTextNetwork
|
||||
from network.cnnTextNetwork import cnnTextNetwork
|
||||
+1
-1
@@ -148,7 +148,7 @@ class Vocab(Configurable):
|
||||
|
||||
|
||||
def __getitem__(self, key):
|
||||
if isinstance(key, basestring):
|
||||
if isinstance(key, str):
|
||||
# Convert the lower case
|
||||
if self.lower_case:
|
||||
key = key.lower()
|
||||
|
||||
Reference in New Issue
Block a user