Ejemplo n.º 1
0
maxlen = 80
batch_size = 32

print('Loading data...')
(X_train, y_train), (X_test, y_test) = imdb.load_data(num_words=nb_tokens)
print(len(X_train), 'train sequences')
print(len(X_test), 'test sequences')

print('Pad sequences (samples x time)')
X_train = sequence.pad_sequences(X_train, maxlen=maxlen)
X_test = sequence.pad_sequences(X_test, maxlen=maxlen)
print('X_train shape:', X_train.shape)
print('X_test shape:', X_test.shape)

print('Build model...')
model = deepmoji_architecture(nb_classes=2, nb_tokens=nb_tokens, maxlen=maxlen)
model.summary()

model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

print('Train...')
model.fit(X_train,
          y_train,
          batch_size=batch_size,
          epochs=15,
          validation_data=(X_test, y_test))
score, acc = model.evaluate(X_test, y_test, batch_size=batch_size)
print('Test score:', score)
print('Test accuracy:', acc)
Ejemplo n.º 2
0
Model: define and load all model-related things
"""
# Specify number of classes used for the classification:
nb_classes = 2
# Load the vocabulary:
with open(vocab_path, 'r') as f:
    vocab = json.load(f)
# Load model specifications:
with open(specs_path, 'r') as f:
    model_specs = json.load(f)
# Define the sentence tokenizer:
st = SentenceTokenizer(vocab, model_specs['maxlen'])
# Define architecture of the model:
model = deepmoji_architecture(nb_classes=nb_classes,
                              nb_tokens=len(vocab),
                              maxlen=model_specs['maxlen'],
                              embed_dropout_rate=0.25,
                              final_dropout_rate=0.5,
                              embed_l2=1E-6)
# Load weights of the model:
load_specific_weights(model=model, weight_path=weights_path)
# Load information about stocks for which we have data issues:
data_issue = pd.read_csv(
    RAW_DATA_PATH + '/data_issue_info.tsv',
    delimiter='\t')
# Load mapping file for the companies:
company_mapping = pd.read_csv(
    RAW_DATA_PATH + "/SP500_Company_Mapping.tsv",
    delimiter="\t")

"""
Information: load information about the stocks and the stock market
Ejemplo n.º 3
0
from deepmoji.model_def import deepmoji_architecture
from sprinklr_global import path, max_nb_words, max_sequence_length

model = deepmoji_architecture(nb_classes=64, nb_tokens=max_nb_words, maxlen=max_sequence_length)
model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])
model.load_weights(path + "model-best")
model.predict()
Ejemplo n.º 4
0
nb_tokens = 20000
maxlen = 80
batch_size = 32

print('Loading data...')
(X_train, y_train), (X_test, y_test) = imdb.load_data(num_words=nb_tokens)
print(len(X_train), 'train sequences')
print(len(X_test), 'test sequences')

print('Pad sequences (samples x time)')
X_train = sequence.pad_sequences(X_train, maxlen=maxlen)
X_test = sequence.pad_sequences(X_test, maxlen=maxlen)
print('X_train shape:', X_train.shape)
print('X_test shape:', X_test.shape)

print('Build model...')
model = deepmoji_architecture(nb_classes=2, nb_tokens=nb_tokens, maxlen=maxlen)
model.summary()

model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

print('Train...')
model.fit(X_train, y_train, batch_size=batch_size, epochs=15,
          validation_data=(X_test, y_test))
score, acc = model.evaluate(X_test, y_test, batch_size=batch_size)
print('Test score:', score)
print('Test accuracy:', acc)