# Coming from python this took a while to figure out

**URL:** <https://discourse.julialang.org/t/coming-from-python-this-took-a-while-to-figure-out/111716>\
**Category:** New to Julia\
**Created:** [March 17, 2024, 6:38am UTC](https://discourse.julialang.org/t/coming-from-python-this-took-a-while-to-figure-out/111716 "2024-03-17T06:38:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fenrir\_Sivar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fenrir_sivar/32/206138_2.png) [@Fenrir\_Sivar](https://discourse.julialang.org/u/Fenrir_Sivar)\
**Post date:** [March 17, 2024, 6:38am UTC](https://discourse.julialang.org/t/coming-from-python-this-took-a-while-to-figure-out/111716/1 "2024-03-17T06:38:57Z")

</div>

```julia
# throws a non descriptive error
prot_alphabet=["R","H","K",
               "D","E",
               "S","T","N","C","Q",
               "C","U","G","P",
               "A","V","I","L","M","F","Y","W"]

using Flux: onehotbatch
tokenise(s) = onehotbatch(s, prot_alphabet)

prot_seq="GAQLLNYASYFAKMAIKLDRKG"
tokenise(prot_seq)

```

vs

```julia
# gives a nice OneHotMatrix
prot_alphabet=['R','H','K',
               'D','E',
               'S','T','N','C','Q',
               'C','U','G','P',
               'A','V','I','L','M','F','Y','W']

using Flux: onehotbatch
tokenise(s) = onehotbatch(s, prot_alphabet)

prot_seq="GAQLLNYASYFAKMAIKLDRKG"
tokenise(prot_seq)

```

its the string vs char of course  
but what to do if I want to hotone encode something where the labels are not single chars but longer strings

---

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [March 17, 2024, 8:18am UTC](https://discourse.julialang.org/t/coming-from-python-this-took-a-while-to-figure-out/111716/2 "2024-03-17T08:18:43Z")

</div>

Here your first input is a String meaning a list of char which is why he wants a vector of char as second input. If you were using a vector of String (or substring ) instead then you would need a vector of String on both

---

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [March 17, 2024, 8:25am UTC](https://discourse.julialang.org/t/coming-from-python-this-took-a-while-to-figure-out/111716/3 "2024-03-17T08:25:03Z")

</div>

In the case you would have a big String and you want to tokenize it you would firt split it then embed it for example for word tokens  
s\_split = split(s," ")  
oh\_s = onehotbatch(s\_split, unique(s\_split))

For special vocab I would still go with a loop to split and recognise parts of the vocab.

---

<div class="post-metadata">

**Author:** ![Fenrir\_Sivar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fenrir_sivar/32/206138_2.png) [@Fenrir\_Sivar](https://discourse.julialang.org/u/Fenrir_Sivar)\
**Post date:** [March 17, 2024, 8:28am UTC](https://discourse.julialang.org/t/coming-from-python-this-took-a-while-to-figure-out/111716/4 "2024-03-17T08:28:11Z")

</div>

Thanks, super clear now. It’s a steep learning curve. but i’ll get there
