How to update the weight about BlockLSTM ?
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 20/100
- Tipo de issue
- Documentação
- Clareza
- Precisa de esclarecimento
- Status de atividade
- Estagnada
- Domínio
- machine-learning
Direção de pesquisa
Comece com o exemplo de Scala fornecido e a chamada BlockLSTM.create; em seguida, inspecione a API Java em busca de BlockLSTMGrad ou de outras operações de gradiente. Execute o exemplo no ambiente Java do TensorFlow e determine se as APIs expostas oferecem suporte à atualização dos tensores de peso exibidos. Considera-se concluído quando o workflow compatível para atualização dos pesos estiver documentado ou quando a limitação da API estiver claramente declarada.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
HI :
now I use BlockLSTM for build lstm layer ,but I don't know how to update the lstm weight parameters , if need use blockLSTMGrad or something to do ,the coda is paste here:
object LstmExample {
def initializeTruncatedNormalTensor(shape: Operand[TInt32], scope: Scope): TFloat32 = {
TruncatedNormal.seed(1000L)
// TruncatedNormal<TFloat32> truncatedNormal = TruncatedNormal.create(scope, shape, TFloat32.DTYPE);
// DataType<TFloat32> DTYPE = DataType.create("FLOAT", 1, 4, TFloat32Impl::mapTensor);
// DataType DTYPE = DataType.valueOf("FLOAT");
val truncatedNormal: TruncatedNormal[TFloat32] = TruncatedNormal.create(scope, shape, classOf[TFloat32])
return truncatedNormal.asTensor
}
private def getWeightMatrix(shape: Operand[TInt32], scope: Scope) = { // Tensor<TFloat32> tensorWeight = TensorValues.initializeTruncatedNormalTensor(shape, scope);
val tensorWeight = TensorValues.initializeTruncatedNormalTensor(shape, scope)
Constant.create(scope, tensorWeight)
}
def printTensor(tensor: Operand[TFloat32],name:String): Unit ={
val data: Array[Float] = TensorResources.extractFloats(tensor.asTensor())
println(s"data:${name}, ${data.mkString(" | ")}")
}
def main(args: Array[String]): Unit = {
val libraryPath = System.getProperty("java.library.path")
System.out.println(libraryPath)
implicit val session = TestSession.createTestSession(TestSession.Mode.EAGER) // EagerSession.create()
implicit val tf = session.getTF // Ops.create(session).withName("test")
implicit val scope = tf.scope()
// val session = EagerSession.create
// val tf = Ops.create(session)
// Scope scope = new Scope(session);
// val scope = session.baseScope()
val rawInputSequence = Array(Array(Array(0.1f, 0.2f)), Array(Array(0.3f, 0.4f))) //shape (timelen, batch_size, num_inputs).
val inputSequence = tf.constant(rawInputSequence)
val inputSize = 2
val cellSize = 5
val maximumTimeLength = 2
val cellShape = Array(1, cellSize)
val cellDims = Constant.vectorOf(scope, cellShape)
val seqLenMax = tf.array(maximumTimeLength)
// Operand<TFloat32> initialCellState = Zeros.create(scope, cellDims, TFloat32.DTYPE);
// Operand<TFloat32> initialHiddenState = Zeros.create(scope, cellDims, TFloat32.DTYPE);
val initialCellState = Zeros.create(scope, cellDims, classOf[TFloat32])
val initialHiddenState = Zeros.create(scope, cellDims, classOf[TFloat32])
val weightShape = Array(inputSize + cellSize, cellSize * 4)
val weightMatrixDims = Constant.vectorOf(scope, weightShape)
val weightMatrix = getWeightMatrix(weightMatrixDims, scope)
// session.print(weightMatrix)
val weightGatesShape = Array(cellSize)
val weightGatesDims = Constant.vectorOf(scope, weightGatesShape)
val weightInputGate = getWeightMatrix(weightGatesDims, scope)
printTensor(weightInputGate,"weightInputGate")
val weightForgetGate = getWeightMatrix(weightGatesDims, scope)
printTensor(weightForgetGate,"weightForgetGate")
val weightOutputGate = getWeightMatrix(weightGatesDims, scope)
printTensor(weightOutputGate ,"weightOutputGate")
val biasShape = Array(cellSize * 4)
val biasDim = Constant.vectorOf(scope, biasShape)
//classOf[TFloat32]
// Operand<TFloat32> bias = Zeros.create(scope, biasDim, TFloat32.DTYPE);
val bias = Zeros.create(scope, biasDim, classOf[TFloat32])
val blockLSTM = BlockLSTM.create(scope, tf.dtypes.cast(seqLenMax, classOf[TInt64]), inputSequence, initialCellState, initialHiddenState, weightMatrix, weightInputGate, weightForgetGate, weightOutputGate, bias)
// session.print(blockLSTM.i)
// println("&&&cs")
// session.print(blockLSTM.cs)
// println("&&&f")
// session.print(blockLSTM.f)
// println("&&&o")
// session.print(blockLSTM.o)
// println("&&&ci")
// session.print(blockLSTM.ci)
// println("&&&co")
// session.print(blockLSTM.co)
// println("&&&h")
// session.print(blockLSTM.h)
thanks for your help
- Linguagem predominante
- Java
- Estrelas
- 928
- Forks
- 227
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de tensorflow/java
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
tensorflow/java#653 · 1 comentário · 4 reações ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
tensorflow/java#621 · 4 comentários ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
tensorflow/java#617 · 3 comentários ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 55/100
tensorflow/java#615 · 1 comentário ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
tensorflow/java#614 · 1 comentário ·
Todas as issues de tensorflow/java
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
infinispan/infinispan#18150 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
untriaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
opensearch-project/k-NN#3597 ·
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100