code: public InstanceList[] split(java.util.Random r, int _nfolds) {
  
          List<Integer> articleIds = newArrayList(instanceArticles.keySet());
          Collections.shuffle(articleIds, r);
  
          final int nrSentences = instanceArticles.size();
          final int nrSentencesPerSplit = (int) (nrSentences / (double) _nfolds);
  
          int runningSplitId = 0;
          int runningSentencesPerSplit = 0;
  
          InstanceList[] splitted = new InstanceList[_nfolds];
          for (int i = 0; i < splitted.length; i++) {
              splitted[i] = new InstanceList(pipe);
          }
          for (int i = 0; i < articleIds.size(); i++) {
  
              // add all sentences from this article
              for (Instance sentence : instanceArticles.get(articleIds.get(i))) {
                  // System.out.println(format("adding {} to split {}",
                  // sentence.name, runningSplitId));
                  splitted[runningSplitId].add(sentence);
                  runningSentencesPerSplit++;
              }
              // move to next split?
              if (runningSentencesPerSplit > nrSentencesPerSplit
                      && runningSplitId < (_nfolds - 1)) {
                  runningSplitId++;
                  runningSentencesPerSplit -= nrSentencesPerSplit;
              }
          }
  
          // some stats
          LOG.debug("{} sentences in {} splits", nrSentences, _nfolds);
          for (InstanceList iList : splitted) {
              LOG.debug("size:: " + iList.size());
          }
  
          return splitted;
      }
docs: Shuffles the elements of this list among several smaller lists.
  
  @param fraction
  A list of numbers (not necessarily summing to 1) which, when
  normalized, correspond to the proportion of elements in each
  returned sublist. This method (and all the split methods) do
  not transfer the Instance weights to the resulting
  InstanceLists.
  @param r
  The source of randomness to use in shuffling.
  @return one <code>InstanceList</code> for each element of
  <code>proportions</code>