Git Product home page Git Product logo

Comments (8)

lin520chong avatar lin520chong commented on September 16, 2024 2

had you resolve this error。can you help give us the method。i replace tf.nn.bidirectional_rnn to tf.nn.bidirectional_dynamic_rnn,it still donot work。

from ner-lstm.

utkrist avatar utkrist commented on September 16, 2024

@gahu1125 It really depends on your use case. If you don't know your nsteps parameter in advance, you can set it None when defining input or output placeholder and use the dynamic one but if you know your max_nstetps in advance and have sufficient gpu memory you can even use the static verison.

I'm posting an snippet from my code for your reference:

def multi_layer_birnn_static(config, input, seq_len, dropout):
    nhidden = config.nb_hidden
    ntags   = config.out_dim
    nsteps  = config.nb_steps
    nlayers = config.nb_layers
    cell    = rnn_cell(config.cell_type)

    # input shape: (batch_size, nsteps, in_dim)
    # Unstack to get a list of 'n_steps' tensors of shape (batch_size, n_input)
    input = tf.unstack(input, nsteps, 1)
    
    def _single_cell():
        _cell = cell(num_units=nhidden, state_is_tuple=True)
        _cell = tf.contrib.rnn.DropoutWrapper(_cell, output_keep_prob=dropout)
        return _cell
        
    fw_cell = tf.contrib.rnn.MultiRNNCell(cells=[_single_cell() for _ in range(nlayers)], state_is_tuple = True)
    bw_cell = tf.contrib.rnn.MultiRNNCell(cells=[_single_cell() for _ in range(nlayers)], state_is_tuple = True)
    
    output, _, _ = tf.contrib.rnn.static_bidirectional_rnn(fw_cell, bw_cell, input ,dtype=tf.float32)
    output = tf.stack(output, 1)
    return output


def multi_layer_birnn_dynamic(config, input, seq_len, dropout):
    nhidden = config.nb_hidden
    ntags   = config.out_dim
    nsteps  = config.nb_steps
    nlayers = config.nb_layers
    cell    = rnn_cell(config.cell_type)

   # permute n_steps and batch_size
   input = tf.transpose(input, [1, 0, 2]) 

    def _single_cell():
        _cell = cell(num_units=nhidden, state_is_tuple=True)
        _cell = tf.contrib.rnn.DropoutWrapper(_cell, output_keep_prob=dropout)
        return _cell
        
    fw_cell = tf.contrib.rnn.MultiRNNCell(cells=[_single_cell() for _ in range(nlayers)], state_is_tuple = True)
    bw_cell = tf.contrib.rnn.MultiRNNCell(cells=[_single_cell() for _ in range(nlayers)], state_is_tuple = True)

    outputs, states = tf.nn.bidirectional_dynamic_rnn(
        cell_fw=fw_cell, 
        cell_bw=bw_cell,
        dtype=tf.float32,
        inputs=input,
        time_major=True, 
        sequence_length=seq_len)
    out_fw, out_bw = outputs
    output = tf.concat([out_fw, out_bw], axis=-1)
    output = tf.transpose(output, [1, 0 ,2])
    return output

from ner-lstm.

swethmandava avatar swethmandava commented on September 16, 2024

https://github.com/swethmandava/text_normalization/blob/master/blstm_new.py May be this can help

from ner-lstm.

nanobyte-dg avatar nanobyte-dg commented on September 16, 2024

@gahu1125 Were you able to resolve the issue? I am also facing the same issue.

from ner-lstm.

aksstar avatar aksstar commented on September 16, 2024

@lin520chong Did you solve this issue ?

from ner-lstm.

Chiang97912 avatar Chiang97912 commented on September 16, 2024

maybe you can get solution from this https://github.com/KeithYin/mycodes/blob/master/tensorflow-piece/diy-multi-layer-bi-rnn.py

from ner-lstm.

sarvy26 avatar sarvy26 commented on September 16, 2024

for tensorflow version 1.10.1 this issue still exists.

from ner-lstm.

gopi1410 avatar gopi1410 commented on September 16, 2024

Updated code here with bidirectional_dynamic_rnn and using TF 1.4
https://github.com/gopi1410/ner-lstm

from ner-lstm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.