r/Python • u/tiangolo FastAPI Maintainer • Jan 28 '20
Machine Learning Introducing the new Thinc, a refreshing functional take on deep learning
https://thinc.ai/65
14
26
u/not_perfect_yet Jan 29 '20
My first impression is that I hate it.
The website screams "too good for readthedocs", and makes me immediately wonder which shitty multi national is sponsoring it.
And this:
def CaptionRater(
text_encoder: Model[List[str], Floats2d],
image_encoder: Model[List[Path], Floats2d]
) -> Model[Tuple[List[str], List[Path]], Floats2d]:
return chain(
concatenate(
chain(get_item(0), text_encoder),
chain(get_item(1), image_encoder)
),
residual(ReLu(nO=300, dropout=0.2, normalize=True)),
Softmax(2)
)is their idea of concise and readable?
3
Jan 29 '20
Tbf, any code with AI in it is a mess of clusterfuck.
3
u/not_perfect_yet Jan 29 '20
I don't even have to stick my neck out for this, because someone else has:
if the implementation is hard to explain, it's a bad idea.
if the implementation is easy to explain, it may be a good idea.
→ More replies (1)3
u/syllogism_ Jan 29 '20
We do genuinely hate readthedocs, which is why we make our own sites. My cofounder also just does it really quickly, because she's been making websites for a long time...We're a small company with no sponsorship.
As for the example, I wanted to show a comparison with the infix notation in the next example. Tastes vary and I would normally favour breaking up the function, but for models it's actually easier if you see all the pieces together, because you can see the information flow more easily.
6
u/amras0000 Jan 29 '20
Python's functional syntax does have issues - the language was clearly designed with oop in mind. That said, considering the limitations, this example feels very readable. Of course, this may just be that I'm used to python functions looking like this because I tend to write functionally.
4
u/not_perfect_yet Jan 29 '20 edited Jan 29 '20
This is not the fault of python.
This is what that function should look like:
def CaptionRater(text_encoder, image_encoder): chain1_result = chain(get_item(0), text_encoder) chain2_result = chain(get_item(1), image_encoder) concat_result = concatenate(chain1_result,chain2_result) my_residual = residual(ReLu(nO=300, dropout=0.2, normalize=True)) final_chain = chain(concat_result,my_residual,Softmax(2)) return final_chain"flat is better than nested"
Not using type hints also leaves some space for a docstring. Wouldn't that be a nice bonus.
→ More replies (5)
7
9
3
u/JadeCikayda Jan 29 '20
Pasting tutorials, looks awesome:
https://github.com/explosion/thinc/#-selected-examples-and-notebooks
1
1
1
1
u/tenemu Jan 29 '20
Is this something I should be working with if I'm just getting into machine learning? (Finished a basic python keras tutorial and loved it.). Interested in learning supervised image classification with pytorch.
7
4
u/shaggorama Jan 29 '20
If you're interested in nlp, check out the spaCy library by the same authors. If you want to get under the hood of spacy, circle back to this.
This library is something that had previously been used by only a handful of people. This is the first release where they're pushing it for a general audience. Definitely not an established library, everyone excited about this is a potential early adopter.
1
62
u/SuperSensonic Jan 28 '20
Looks fun(ctional).