Пример #1
0
def train_input():
    X_train, Y_train = read_data.read_train_data()
    Y_train = np.expand_dims(Y_train, axis=-1)
    return X_train, Y_train
Пример #2
0
import tensorflow as tf
from tensorflow._api.v1.keras import layers
import read_data

x_train, y_train = read_data.read_train_data()
x_test, y_test = read_data.read_test_data()
num, H, W, _ = x_train.shape

model = tf.keras.models.Sequential([
    tf.keras.layers.Conv2D(filters=16,
                           kernel_size=3,
                           strides=(1, 1),
                           padding='valid',
                           data_format='channels_last',
                           activation='relu',
                           use_bias=True,
                           input_shape=(H, W, 1)),
    tf.keras.layers.Conv2D(filters=32,
                           kernel_size=3,
                           strides=(1, 1),
                           padding='same',
                           data_format='channels_last',
                           activation='relu',
                           use_bias=True,
                           input_shape=(H - 2, W - 2, 16)),
    tf.keras.layers.Conv2D(filters=64,
                           kernel_size=3,
                           strides=(1, 1),
                           padding='same',
                           data_format='channels_last',
                           activation='relu',
Пример #3
0
import random
import csv
"""
This file is to plot the relationship between k and prediciton:
"""


def distance(data1, data2):
    sum = 0.
    for i in range(len(data1)):
        sum += math.pow(data1[i] - data2[i], 2)
    return math.sqrt(sum)


# read data:
data, train_data, validation_data, test_data, y, y_train, y_validation, y_test = read_data.read_train_data(
)

res = []
train_data_sample = []
y_train_sample = []
# read data from csv files:
with open('model_data.csv', newline='') as csvfile:
    reader = csv.reader(csvfile, delimiter=" ", quotechar='|')
    for row in reader:
        train_data_sample.append((list(map(int, row[0].split(',')))))
with open('model_label.csv', newline='') as csvfile:
    reader = csv.reader(csvfile, delimiter=" ", quotechar='|')
    for row in reader:
        # only 1 row:
        y_train_sample = (list(map(int, row[0].split(','))))
Пример #4
0
                pad_sequence(list(reversed([init_vector(c) for c in _ds.bw])),
                             _max_length_bw))
        _input_fw = np.array(_input_fw)
        _input_bw = np.array(_input_bw)
        _length_fw = np.array(_length_fw)
        _length_bw = np.array(_length_bw)
        _targets = np.array(_targets)
        _target_ids = np.array(_target_ids)
        _nb_senses = np.array(_nb_senses)
        return _input_fw, _input_bw, _length_fw, _length_bw, _targets, \
               _target_ids, _nb_senses, _output_fw_idx, _output_bw_idx


if __name__ == "__main__":
    TRAIN_DATA, LEMMA2SENSES, LEMMA2INT = read_data.read_train_data(
        read_data.read_x("ALL.data.xml")[0],
        read_data.read_y("ALL.gold.key.bnids.txt"), True)
    MAX_NB_SENSES = max([len(LEMMA2SENSES[k]) for k in LEMMA2SENSES
                         ])  # max number of senses among all target words
    MAX_NB_TARGETS = len(LEMMA2SENSES)  # how many target words

    # load word embedding initialized by init_emb (run init_emb first if you don't have this file)
    with open('pretrained_vectors/needed' + '.pkl', 'rb') as f:
        WORD_VECTORS = pickle.load(f)
    WORD_VECTORS["_drop_"] = np.random.uniform(
        -0.1, 0.1, 300)  # add drop vector for drop words

    NB_EPOCHS = 100  # number of epochs to train
    x_val, y_val, _ = read_data.read_test_data(
        LEMMA2INT, LEMMA2SENSES, WORD_VECTORS)  # read validation data
    """train models"""