News for hackers. Stuff that matters.
Re:Show HN: Thinc, a new deep learning library by the makers... by syllogism on Wednesday January 29, 2020 @03:28AM (#22178530)
The best answer is, "with some difficulty". I've written a bit about the struggles here: https://thinc.ai/docs/usage-type-checking#model-types

There are basically two approaches, TypeVar and overload. You probably want TyepVar if you have exactly that sort of situations, but there's a lot about type vars I still don't understand, and the docs say almost nothing. The problem is the responsibility is kind of split in two places: the Python typing module doesn't really take any responsibility for usage, and mypy sees it as not mypy-specific, so neither describes it very well.

Our current solution is to avoid being fully variadic in the tensor type, and instead have a limited number of subclasses. This allows us to get by with overload, because we can enumerate out the set of argument-to-return mappings. This is especially important for the numpy API where you often have to overload on the types and values of other arguments, e.g. if you pass axis=(0, 1), you'll get a different rank of tensor back than if you had written axis=-1.

You can see the gory details of how I've done the numpy types here: https://github.com/explosion/thinc/blob/master/thinc/types.p...

Re:Show HN: Thinc, a new deep learning library by the makers... by ipsum2 on Wednesday January 29, 2020 @02:47PM (#22184993)
Thanks for the detailed reply and the links!