home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / fest-141.zip / festival / lib / phrase.scm < prev    next >
Text File  |  1999-06-17  |  7KB  |  172 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;                                                                       ;;
  3. ;;;                Centre for Speech Technology Research                  ;;
  4. ;;;                     University of Edinburgh, UK                       ;;
  5. ;;;                       Copyright (c) 1996,1997                         ;;
  6. ;;;                        All Rights Reserved.                           ;;
  7. ;;;                                                                       ;;
  8. ;;;  Permission is hereby granted, free of charge, to use and distribute  ;;
  9. ;;;  this software and its documentation without restriction, including   ;;
  10. ;;;  without limitation the rights to use, copy, modify, merge, publish,  ;;
  11. ;;;  distribute, sublicense, and/or sell copies of this work, and to      ;;
  12. ;;;  permit persons to whom this work is furnished to do so, subject to   ;;
  13. ;;;  the following conditions:                                            ;;
  14. ;;;   1. The code must retain the above copyright notice, this list of    ;;
  15. ;;;      conditions and the following disclaimer.                         ;;
  16. ;;;   2. Any modifications must be clearly marked as such.                ;;
  17. ;;;   3. Original authors' names are not deleted.                         ;;
  18. ;;;   4. The authors' names are not used to endorse or promote products   ;;
  19. ;;;      derived from this software without specific prior written        ;;
  20. ;;;      permission.                                                      ;;
  21. ;;;                                                                       ;;
  22. ;;;  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        ;;
  23. ;;;  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      ;;
  24. ;;;  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   ;;
  25. ;;;  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     ;;
  26. ;;;  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    ;;
  27. ;;;  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   ;;
  28. ;;;  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          ;;
  29. ;;;  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       ;;
  30. ;;;  THIS SOFTWARE.                                                       ;;
  31. ;;;                                                                       ;;
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. ;;;
  34. ;;;   Phrase boundary prediction.
  35. ;;;   
  36. ;;;   Two methods supported, if POS is enabled we use ngrams for that
  37. ;;;   otherwise we use a CART tree
  38. ;;;
  39. ;;;   Models trained from the IBM/Lancaster Spoken English Corpus and 
  40. ;;;   Boston University's FM Radio Corpus.
  41.  
  42. ;;;
  43. ;;;  Here's a very simple CART tree for predicting phrase breaks
  44. ;;;  based on punctuation only
  45. ;;;
  46. (set! simple_phrase_cart_tree
  47. '
  48. ((lisp_token_end_punc in ("?" "." ":"))
  49.   ((BB))
  50.   ((lisp_token_end_punc in ("'" "\"" "," ";"))
  51.    ((B))
  52.    ((n.name is 0)  ;; end of utterance
  53.     ((BB))
  54.     ((NB))))))
  55.  
  56. (define (token_end_punc word)
  57.   "(token_end_punc UTT WORD)
  58. If punctuation at end of related Token and if WORD is last word
  59. in Token return punc, otherwise 0."
  60.   (if (item.relation.next word "Token")
  61.       "0"
  62.       (item.feat word "R:Token.parent.punc")))
  63.  
  64. ;;;  This is a simple CART tree used after boundaries are predicted
  65. ;;;  by the probabilistic method to get two levels of break
  66. (set! english_phrase_type_tree
  67. '((pbreak is NB)
  68.   ((num_break is 1)
  69.    ((mB))
  70.    ((R:Token.parent.EMPH is 1)
  71.     ((NB))
  72.     ((n.R:Token.parent.EMPH is 1)
  73.      ((NB))
  74.      ((NB)))))
  75.   ((pbreak is BB)
  76.    ((BB))
  77.    ((pbreak is mB)
  78.     ((mB))
  79.     ((name in ("." "!" "?"));; only (potentially) change Bs to BBs
  80.      ((BB))
  81.      ((B)))))))
  82.  
  83. (set! f2b_phrase_cart_tree
  84. '
  85. ((gpos is punc)
  86.  (((1 0.00238095) (3 0) (4 0.997619) B))
  87.  (((4 0.00238095) (3 0) (1 0.997619) NB))))
  88.  
  89. ;;;  For more detailed prediction of phrase breaks we use POS and
  90. ;;;  probability distribution of breaks
  91. ;;;  These models were trained using data from the Lancaster/IBM
  92. ;;;  Spoken English Corpus
  93.  
  94. (require 'pos)   ;; for part of speech map
  95.  
  96. (defvar pbreak_ngram_dir libdir
  97.   "pbreak_ngram_dir
  98.   The directory containing the ngram models for predicting phrase
  99.   breaks.  By default this is the standard library directory.")
  100.  
  101. (defvar english_phr_break_params
  102.   (list
  103.    ;; The name and filename off the ngram with the a priori ngram model
  104.    ;; for predicting phrase breaks in the Phrasify module.  This model should 
  105.    ;; predict probability distributions for B and NB given some context of 
  106.    ;; part of  speech tags.
  107.    (list 'pos_ngram_name 'english_break_pos_ngram)
  108.    (list 'pos_ngram_filename
  109.      (path-append pbreak_ngram_dir "sec.ts20.quad.ngrambin"))
  110.    ;; The name and filename of the ngram  containing the a posteriori ngram
  111.    ;; for predicting phrase breaks in the Phrasify module.  This module should
  112.    ;; predict probability distributions for B and NB given previous B and
  113.    ;; NBs.
  114.    (list 'break_ngram_name 'english_break_ngram)
  115.    (list 'break_ngram_filename
  116.      (path-append pbreak_ngram_dir "sec.B.hept.ngrambin"))
  117.    ;; A weighting factor for breaks in the break/non-break ngram.
  118.    (list 'gram_scale_s 0.59)
  119.    ;; When Phrase_Method is prob_models, this tree, if set is used to 
  120.    ;; potentially predict phrase type.  At least some prob_models only
  121.    ;; predict B or NB, this tree may be used to change some Bs into
  122.    ;; BBs.  If it is nil, the pbreak value predicted by prob_models
  123.    ;; remains the same.
  124.    (list 'phrase_type_tree english_phrase_type_tree)
  125.    ;; A list of tags used in identifying breaks.  Typically B and NB (and
  126.    ;; BB).  This should be the alphabet of the ngram identified in
  127.    ;; break_ngram_name
  128.    (list 'break_tags '(B NB))
  129.    (list 'pos_map english_pos_map_wp39_to_wp20)
  130.    )
  131.   "english_phr_break_params
  132. Parameters for English phrase break statistical model.")
  133.  
  134. (defvar phr_break_params nil
  135.   "phr_break_params
  136. Parameters for phrase break statistical model.  This is typcal set by
  137. a voice selection function to the parameters for a particular model.")
  138.  
  139. ;;;
  140. ;;; Declaration of some features 
  141. ;;; 
  142.  
  143. (def_feature_docstring 
  144.   'Word.pbreak
  145.   "Word.pbreak
  146.   Result from statistical phrasing module, may be B or NB denoting
  147.   phrase break or non-phrase break after the word.")
  148.  
  149. (def_feature_docstring 
  150.   'Word.pbreak_score
  151.   "Word.pbreak_score
  152.   Log likelihood score from statistical phrasing module, for pbreak
  153.   value.")
  154.  
  155. (def_feature_docstring 
  156.   'Word.blevel
  157.   "Word.blevel
  158.   A crude translation of phrase break into ToBI like phrase level.
  159.   Values may be 0,1,2,3,4.")
  160.  
  161. (define (Phrasify utt)
  162. "(Phrasify utt)                                
  163. Construct phrasify over Words module."
  164.   (let ((rval (apply_method 'Phrasify_Method utt)))
  165.     (cond
  166.      (rval rval) ;; new style
  167.      (t
  168.       (Classic_Phrasify utt)))))
  169.  
  170.  
  171. (provide 'phrase)
  172.