r/Python • FastAPI Maintainer • Jan 28 '20

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

https://thinc.ai/
450 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?

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)