public static InstanceList readFromFile(String inputfile) throws IOException {
    BufferedReader in = new BufferedReader(new FileReader(inputfile));

    InstanceList instanceList = new InstanceList();

    String line;

    while ((line = in.readLine()) != null) {
      String tokens[] = line.split(" ");

      int label = Integer.valueOf(tokens[0]);

      Instance ins = new Instance(label);

      for (int i = 1; i < tokens.length; i++) {
        String pair[] = tokens[i].split(":");

        int attr = Integer.valueOf(pair[0]);
        double value = Double.valueOf(pair[1]);

        ins.addAttribute(attr, value);

        instanceList.addInstance(ins);
      }
    }

    return instanceList;
  }