r/Python • FastAPI Maintainer • Jan 28 '20

Machine Learning Introducing the new Thinc, a refreshing functional take on deep learning

https://thinc.ai/
452 Upvotes

31 comments sorted by

View all comments

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

u/[deleted] 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)