2017-06-18 3 views
0

Ich arbeite an Bigramm-basierte LSTM.Verwendung von Tensorflow sampled_softmax_loss

Seit ich Embedding eingeführt habe, musste ich die richtige Verlustfunktion wählen. Hier ist meine Wahl:

loss=tf.reduce_mean(tf.nn.sampled_softmax_loss(weights=softmax_weights,\ 
       biases=softmax_biases, \ 
       labels=tf.concat(train_labels,0),\ 
       inputs=logits,\ 
       num_sampled=num_sampled,\ 
       num_classes=vocabulary_size)) 

Ich bin vor Etiketten Tensor Dimension Problem Fehler:

Logits hat diese Form: (640, 13)
Etiketten hat diese Form Tensor ("concat_2: 0", Form = (640, 27), dtype = float32)
ich habe auch versucht

labels==tf.reshape(tf.concat(train_labels,0),[-1]) 

Für beide Fälle, erhalte ich eine Fehlermeldung:

Für den ersten Fall, Fehler sind:

   Dimension must be 1 but is 27 for 
       'sampled_softmax_loss/ComputeAccidentalHits' (op: 
       'ComputeAccidentalHits') with input shapes: [640,27], [20]. 

Für den zweiten Fall, Fehler sind:

  Shape must be rank 2 but is rank 1 for 
      'sampled_softmax_loss/LogUniformCandidateSampler' (op: 
      'LogUniformCandidateSampler') with input shapes: [17280]. 

Hier meine Parameter sind:

  640 = batch_size *num_enrollings =64*10 
      27 = vocabulary_size (I am implementing first Embedding on single character as vocabulary. 
      20 is num_sampled of the loss function. 
      13 = embedding_size 

Warum tf.nn.sampled_softmax_loss Akzeptiert keine Etiketten mit 1 Dimension?

tf Version ist 1.0.1 Python-Version: 2.7

Antwort

0

Lösung gefunden.

Ich fütterte sampled_softmax_loss mit Etiketten mit einem heißen Format. Die Dinge liefen mit der einfachen Argmax-Funktion, die auf die Etiketten angewendet wurde

Verwandte Themen