예제 #1
0
    W1 = tf.Variable(w2v, trainable=True)
    X_embedding = tf.nn.embedding_lookup(W1, X)
    X_embedding = X_embedding[..., tf.newaxis]
if args.tf_embedding_type == 'multi-channel':
    W1 = tf.Variable(w2v, trainable=True)
    W2 = tf.Variable(w2v, trainable=False)
    X_1 = tf.nn.embedding_lookup(W1, X)
    X_2 = tf.nn.embedding_lookup(W2, X)
    X_1 = X_1[..., tf.newaxis]
    X_2 = X_2[..., tf.newaxis]
    X_embedding = tf.concat([X_1, X_2], axis=-1)

tf.logging.info("input dimension:{}".format(X_embedding.get_shape()))

if args.tf_model_type == 'capsule-A':
    poses, activations = capsule_model_A(X_embedding, args.num_classes)
if args.tf_model_type == 'capsule-B':
    poses, activations = capsule_model_B(X_embedding, args.num_classes)
if args.tf_model_type == 'CNN':
    poses, activations = baseline_model_cnn(X_embedding, args.num_classes)
if args.tf_model_type == 'KIMCNN':
    poses, activations = baseline_model_kimcnn(X_embedding, args.max_sent,
                                               args.num_classes)

if args.tf_loss_type == 'spread_loss':
    loss = spread_loss(y, activations, margin)
if args.tf_loss_type == 'margin_loss':
    loss = margin_loss(y, activations)
if args.tf_loss_type == 'cross_entropy':
    loss = cross_entropy(y, activations)
예제 #2
0
파일: main.py 프로젝트: qq345736500/wh
    W1 = tf.Variable(w2v, trainable = True)
    X_embedding = tf.nn.embedding_lookup(W1, X)
    X_embedding = X_embedding[...,tf.newaxis] 
if args.embedding_type == 'multi-channel':
    W1 = tf.Variable(w2v, trainable = True)
    W2 = tf.Variable(w2v, trainable = False)
    X_1 = tf.nn.embedding_lookup(W1, X)
    X_2 = tf.nn.embedding_lookup(W2, X) 
    X_1 = X_1[...,tf.newaxis]
    X_2 = X_2[...,tf.newaxis]
    X_embedding = tf.concat([X_1,X_2],axis=-1)

tf.logging.info("input dimension:{}".format(X_embedding.get_shape()))

if args.model_type == 'capsule-A':    
    poses, activations = capsule_model_A(X_embedding, args.num_classes)    
if args.model_type == 'capsule-B':    
    poses, activations = capsule_model_B(X_embedding, args.num_classes)    
if args.model_type == 'CNN':    
    poses, activations = baseline_model_cnn(X_embedding, args.num_classes)
if args.model_type == 'KIMCNN':    
    poses, activations = baseline_model_kimcnn(X_embedding, args.max_sent, args.num_classes)   
    
if args.loss_type == 'spread_loss':
    loss = spread_loss(y, activations, margin)
if args.loss_type == 'margin_loss':    
    loss = margin_loss(y, activations)
if args.loss_type == 'cross_entropy':
    loss = cross_entropy(y, activations)

y_pred = tf.argmax(activations, axis=1, name="y_proba")