# Transformer/Attention-NLP

**URL:** <https://community.konduit.ai/t/transformer-attention-nlp/740>\
**Category:** Uncategorized\
**Created:** [July 21, 2020, 5:44pm UTC](https://community.konduit.ai/t/transformer-attention-nlp/740 "2020-07-21T17:44:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![data-llectual](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/data-llectual/32/195_2.png) [@data-llectual](https://community.konduit.ai/u/data-llectual)\
**Post date:** [July 21, 2020, 5:44pm UTC](https://community.konduit.ai/t/transformer-attention-nlp/740/1 "2020-07-21T17:44:20Z")

</div>

Hello,

Can you please point me to end to end examples that would use transformer layer and multihead attention with dl4j.

Thanks  
Ravi.

---

<div class="post-metadata">

**Author:** ![data-llectual](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/data-llectual/32/195_2.png) [@data-llectual](https://community.konduit.ai/u/data-llectual)\
**Post date:** [July 21, 2020, 8:10pm UTC](https://community.konduit.ai/t/transformer-attention-nlp/740/2 "2020-07-21T20:10:35Z")

</div>

Trying to build following example: [Text classification with Transformer](https://keras.io/examples/nlp/text_classification_with_transformer/) using dl4j

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [July 23, 2020, 4:04am UTC](https://community.konduit.ai/t/transformer-attention-nlp/740/3 "2020-07-23T04:04:45Z")

</div>

All attention models can be found here:

> **[Search · attention · eclipse/deeplearning4j-examples](https://github.com/eclipse/deeplearning4j-examples/search?q=attention&unscoped_q=attention)**
>
> Deeplearning4j Examples (DL4J, DL4J Spark, DataVec) - Search · attention · eclipse/deeplearning4j-examples

I would also suggest running keras import to see if that fits your use case:  
[https://deeplearning4j.konduit.ai/keras-import/overview](https://deeplearning4j.konduit.ai/keras-import/overview)

---

<div class="post-metadata">

**Author:** ![data-llectual](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/data-llectual/32/195_2.png) [@data-llectual](https://community.konduit.ai/u/data-llectual)\
**Post date:** [July 23, 2020, 6:46pm UTC](https://community.konduit.ai/t/transformer-attention-nlp/740/4 "2020-07-23T18:46:34Z")

</div>

Thanks for the response - I am trying to build attention/transformer natively using java only. I couldn’t find any example that would show how to do that.  
Are you suggesting/encouraging that attention models be implemented in keras, and loaded as keras layer in dl4j something like a hybrid approach?

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [November 22, 2020, 4:32am UTC](https://community.konduit.ai/t/transformer-attention-nlp/740/5 "2020-11-22T04:32:54Z")

</div>

@data-llectual (sorry just catching up on the forum a bit and just realized I didn’t get a notification for this, I’ll just answer this for future readers), your best bet in this case would be to look at some of our test cases:

> <https://github.com/eclipse/deeplearning4j/blob/881a672fa13f3b37177eb2ea023e39b0de893645/deeplearning4j/deeplearning4j-core/src/test/java/org/deeplearning4j/nn/transferlearning/TransferLearningMLNTest.java#L705>

We need to build out docs, but there are actually layers for this:

> **[Search · Attention · eclipse/deeplearning4j](https://github.com/eclipse/deeplearning4j/search?l=Java&q=Attention)**
>
> Suite of tools for deploying and training deep learning models using the JVM. Highlights include model import for keras, tensorflow, and onnx/pytorch, a modular and tiny c++ library for running mat...
