Composing the two-voice counterpoint (LAI)

Application domain: Composing music
Further specification: Data sets of positive and negative examples
Pointers: Contact Uros Pompe uros.pompe@fri.
Data complexity: Three sets of positive examples (151, 316, 505) and three of negative examples (156, 2284, 19912)
Data format: Prolog

Counterpoint is a technique of multi-voice composing that simultaneously uses two or more musical lines (melodies) which are musically autonomous but mutually accord with respect to certain rules. In our study we were concerned with a small part of that huge musical theory: a two-voice counterpoint with a limited style defined by the rules that were posted by Palestrino (1526-1594) (Morris, 1922; Orem, 1937). Besides, for the purpose of simplicity, we restricted our study to whole notes against whole notes in C-major and treble clef. Figure 1 represents an example of such counterpoint piece.

Figure 1: An example cantus firmus with the counterpoint

The problem of composing the two-voice counterpoint is therefore: for a given basic melody, called cantus firmus, write the second voice, i.e. the counterpoint, in such a way that the constraints of the two-voice counterpoint are satisfied. To be able to compose the counterpoint, one has to use negative rules that prohibit (many) incorrect counterpoints, and positive rules which guide the composing towards better counterpoints. Of course, ``better'' in music is rather a subjective characteristic which makes the learning of positive rules less defined and more fuzzy. Different composers use different positive rules (and often contradict negative rules) and create their own style of composing.

Learning the two-voice counterpoint was studied also by other researchers. Widmer (1988) uses context-free grammars to represent the relation between the basic melody and the counterpoint and uses also the advanced and complex background knowledge to learn the apprentice system. Dobnikar (1994) uses the manually coded set of rules in an expert system for composing the counterpoint. He preliminary studied also the use of ILP to learn the rules from training instances.

The data

To induce negative and positive rules using an ILP system one needs to have: In our case we selected the target predicates:

segment(CfNote, CpNote, PreCfNote, TargetPreCpNote)
bad(CfNote, CpNote, PreCfNote, TargetPreCpNote)

Figure 2: An example of the segment relation

'Cf' stands for cantus firmus and 'Cp' for counterpoint. The relation is illustrated with Figure 2. Predicate ``segment'' defines positive rules and predicate ``bad'' defines negative rules. The rules for the target predicates enable one to compose the counterpoint from cantus firmus and the ending note of the counterpoint (which satisfies the rules of ending harmoniousness) by iteratively applying the positive rules to complete the first non-completed note of the counterpoint starting from right to left with further restrictions dictated by negative rules. If the set of positive rules is empty or nondeterministic, all possible counterpoints are generated that do not satisfy the negative rules. Besides automatically generated negative rules, we used also the following rules from the musical theory to restrict the set of possible counterpoints for a given cantus firmus:

  1. The rule of ending harmoniousness.
  2. The rule of starting harmoniousness.
  3. The rule of at most three successive tercas.
  4. The rules about successive jumps.
Note that none of the above rules can be described only with predicates segment and bad.

The background knowledge includes the basic musical knowledge:

is_interval(Note1, Note2, Interval)
defines the interval between two notes.
is_interval1(Note1, Note2, Interval)
defines the interval between two notes

where Note2 is higher than Note1.
is_quality(Interval, Quality)
defines the quality of an interval.
We used altogether 13 different Notes, 12 different intervals, and 3 different qualities.

Note that due to 4 arguments of the target predicate, each with 13 possible values, the complete space consists of tex2html_wrap_inline1685 instances. We had available a database from which we were able to generate up to 505 positive instances and up to 19.912 negative instances (Makse, 1994). The closed world assumption for the generation of the negative instances is inappropriate for two reasons in this case. First, not all the positive examples are given, and second, the domain itself is not crisp, there are examples which can not be classified as either positive or negative since sometimes the rules can be broken to emphasize more the artistic component of the counterpoint.

SFOIL experiments

In our experiments we generated several sets of positive training instances, containing 151, 316, and 505 positive instances, and several sets of negative training instances, containing 156, 2.284, and 19.912 negative instances. We combined positive and negative training sets in all possible ways and ran SFOIL on these sets. The task was to learn positive rules (relation segment/4) and negative rules (relation bad/4). SFOIL, running on Sun Sparc-10, was able to generate rules in time ranging from few seconds for the smaller problem (151+/156- for segment and 156+/151- for bad) up to 5 hours for the largest problem (505+/19.912- for segment and 19.912+/505- for bad). The hypotheses were made of up to 30 clauses for good and up to 90 clauses for bad predicate. An example of the hypothesis for the smallest problem (good 151+/156-) is
  segment(A,B,C,D) :-
We generated counterpoints for several tens of basic melodies. Counterpoints were generated in an exhaustive manner: all possible counterpoints that were allowed by at least one positive rule (segment) and were not covered by any negative rule (bad). These counterpoints were then evaluated by two professional musicians and three non-musicians.

For almost each of the counterpoints the musicians were able to detect a certain pitfall, mostly related to the problem of the ending of the counterpoint. Note that the ending sequence was not treated separately by our knowledge representation. However, non-musicians considered almost all counterpoints nice and only in few exceptional cases they were able to recognize the pitfalls that were discovered by the musicians.

As already stressed in Section 2, the quality of composing can be only subjectively evaluated. Overall, the professional musicians and non-musicians considered our system an acceptable junior composer.


  1. Dobnikar A. (1994) Two-voice counterpoint composition defined with inductive learning, Proc. 3rd Electrotech. and Computer Sc. Conf. ERK-94, Portoroz, Slovenia, Sept. 1994, Vol.B, pp.151-154.
  2. Makse T. (1994) An application of ILP in music, B.Sc. thesis (in slovene), University of Ljubljana, FER.
  3. Morris R.O. (1922) Contrapuntal technique in the 16th century, Oxford University Press.
  4. Orem P.W. (1937) The art of interweaving melodies, a first method of counterpoint, Philadelphia, Theodore Presser Co.
  5. Pompe U., Kovacic M., Kononenko I. (1993) SFOIL: Stochastic approach to inductive logic programming, Proc. Slovenian Conf. on Electrr. Eng. and Computer Science ERK-93, Portoroz, Slovenia, Sept. 1993, Vol.B, pp.189-192.
  6. Widmer G. (1988) A knowledge-based approach to machine learning in a subfield of tonal music. Intern. School for the Synthesis of Expert's Knowledge ISSEK-88, Udine, Italy.

back to index