質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

0回答

745閲覧

kerasのエラー ValueError: Initializer for variable embedding_11/embeddings/ is from inside a control-flo

merons

総合スコア11

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2019/07/01 13:03

解決方法を知っている方が居れば、教えてくれると本当に助かります。

ValueError: Initializer for variable embedding_11/embeddings/ is from inside a control-flow construct, such as a loop or conditional. When creating a variable inside a loop or conditional, use a lambda as the initializer.

下記がソースコードです。

#単語ファイルロード with open('words.pickle', 'rb') as ff : words=pickle.load(ff) #Encoder Inputデータをロード with open('e.pickle', 'rb') as f : e = pickle.load(f) #Decoder Inputデータをロード with open('d.pickle', 'rb') as g : d = pickle.load(g) #ラベルデータをロード with open('t.pickle', 'rb') as h : t = pickle.load(h) #maxlenロード with open('maxlen.pickle', 'rb') as maxlen : [maxlen_e, maxlen_d] = pickle.load(maxlen) vec_dim = 400 input_dim = len(words) output_dim = input_dim n_hidden = int(vec_dim*2 ) #隠れ層の次元 dialog = Dialog(maxlen_e, 1, n_hidden, input_dim, vec_dim, output_dim) model,encoder_model,decoder_model=dialog.create_model() plot_model(encoder_model, show_shapes=True,to_file='seq2seq01_encoder.png') plot_model(decoder_model, show_shapes=True,to_file='seq2seq01_decoder.png') emb_param='param_seq2seq01.hdf5' model.load_weights(emb_param) #パラメータセット sys.stdin = codecs.getreader('utf_8')(sys.stdin) # Use Juman++ in subprocess mode jumanpp = Juman() while True: cns_input = input(">> ") if cns_input == "end": print("終了") break result = jumanpp.analysis(cns_input) input_text=[] for mrph in result.mrph_list(): input_text.append(mrph.midasi) mat_input=np.array(input_text) #入力データe_inputに入力文の単語インデックスを設定 e_input=np.zeros((1,maxlen_e)) for i in range(0,len(mat_input)) : if mat_input[i] in words : e_input[0,i] = word_indices[mat_input[i]] else : e_input[0,i] = word_indices['UNK'] input_sentence

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問