I've started reading a machine learning book since a few days ago, and I've learned about how it can be used for classification/regression/etc. However, I am unsure if it will be able to handle the task I want to accomplish.

My goal is to build a machine learning algorithm that predicts the return type of a method based on its name and other information. For example, if someone is writing


in an IDE, and GetUsers() is not yet defined, I might want to predict that its return type is List<User> and offer autocompletion based on that. I plan to pre-train my model on lots of code on the web, where it will try to guess the type, and then compare it against the actual type (it would be a supervised training model).

My problem is: I'm not sure how to model this as a classification/regression task. A library may have many types, plus you can nest generic types like so: Task<List<User>> to build an infinite number of types.

How should I approach this problem?

  • You should "look into" natural language processing for that and you'll need to somehow convey semantic information about at least certain types to your system (list -> "has many" -> plural). Jan 6, 2018 at 1:34
  • 1
    @DanielJour I don't think that's necessary. Shouldn't ML be able to detect patterns like "methods that have a word ending in s often return List", and then offer suggestions accordingly, without ever understanding the semantic meaning of List?
    – James Ko
    Jan 6, 2018 at 2:01
  • 1
    You need some way to structure the knowledge that you want to learn. This also applies to the way you present the input data (what kind of "features" do you expose). The more "structure" you provide the more "initial knowledge" (including potential bias or even misunderstanding) for your ml system to work with. "word ending in s" ... set status, get status, launch missiles, print lines, process, ... Jan 6, 2018 at 2:22
  • What you're describing is essentially "type inference," a technique that's available in any compiler that supports it. Jan 10, 2018 at 17:49


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.