public SparseVector convertToSparseVector(ImmutableOutputInfo<MultiLabel> info) {
        if (!(info instanceof ImmutableMultiLabelInfo)) {
            throw new IllegalStateException("Unexpected info type, found " + info.getClass().getName() + ", expected " + ImmutableMultiLabelInfo.class.getName());
        } else {
            ImmutableMultiLabelInfo imInfo = (ImmutableMultiLabelInfo) info;
            Map<Integer, Double> values = new HashMap<>();

            for (Label l : labels) {
                int i = imInfo.getID(l.getLabel());
                if (i != -1) {
                    double score = l.getScore();
                    // A NaN score means this label was constructed without one, meaning it's a ground truth label.
                    if (Double.isNaN(score)) {
                        score = 1.0;
                    }
                    Double t = values.put(i,score);
                    if (t != null) {
                        throw new IllegalArgumentException("Duplicate label ids found for id " + i + ", mapping to Label '" + l.getLabel() + "'");
                    }
                } else {
                    throw new IllegalArgumentException("Unknown label '" + l.getLabel() + "' which was not recognised by the supplied info object, info = " + info.toString());
                }
            }

            return SparseVector.createSparseVector(info.size(), values);
        }
    }
@Test
    public void testToSparseVector() {
        MultiLabel ab = label("a","b");
        MultiLabel abc = label("c","b","a");
        MultiLabel empty = label();
        MultiLabel d = label("d");
        MultiLabel e = label("e");
        MultiLabel de = label("d","e");

        ImmutableOutputInfo<MultiLabel> domain = mkDomain(ab,abc,d);

        SparseVector abVec = ab.convertToSparseVector(domain);
        assertEquals(4,abVec.size());
        assertEquals(2,abVec.numActiveElements());

        SparseVector abcVec = abc.convertToSparseVector(domain);
        assertEquals(4,abcVec.size());
        assertEquals(3,abcVec.numActiveElements());

        SparseVector emptyVec = empty.convertToSparseVector(domain);
        assertEquals(4,emptyVec.size());
        assertEquals(0,emptyVec.numActiveElements());

        SparseVector dVec = d.convertToSparseVector(domain);
        assertEquals(4,dVec.size());
        assertEquals(1,dVec.numActiveElements());

        assertThrows(IllegalArgumentException.class,() -> e.convertToSparseVector(domain));
        assertThrows(IllegalArgumentException.class,() -> de.convertToSparseVector(domain));
    }