Skip to content

Commit

Permalink
Let user configure model weights
Browse files Browse the repository at this point in the history
  • Loading branch information
brianshef committed Dec 5, 2019
1 parent 9dabc40 commit 944f765
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

A [Markov Chain](https://en.wikipedia.org/wiki/Markov_chain) generator based on song lyrics ( originally [Coheed and Cambria](https://www.coheedandcambria.com) ), written in Python 3. Also mixes in text from the artist's wiki page in order to give the sentences a better structure.

Feel free to play around with the relative model weights!

## Prerequisites

- Python 3.7+
Expand All @@ -24,17 +22,22 @@ Alternatively, set up a `.env` file with the environment variable set. `pipenv`

```
usage: main.py [-h] --artist ARTIST --wiki WIKI [--songs SONGS]
[--number NUMBER]
[--number NUMBER] [--lyric-weight LYRIC_WEIGHT]
[--wiki-weight WIKI_WEIGHT]
A Markov Chain generator based on song lyrics. Also mixes in text from the
artist Wikipedia page in order to give the sentences a better structure.
Adjust the weights using the option to play with the relative amounts of
material used in rendering the final model.
optional arguments:
-h, --help show this help message and exit
--artist ARTIST, -a ARTIST
--wiki WIKI, -w WIKI
--songs SONGS, -s SONGS
--number NUMBER, -n NUMBER
--lyric-weight LYRIC_WEIGHT, -p LYRIC_WEIGHT
--wiki-weight WIKI_WEIGHT, -q WIKI_WEIGHT
Best invoked like pipenv run python main.py, OR pipenv run python main.py
--artist "Coheed and Cambria" --wiki "Coheed_and_Cambria" | tee output.txt
Expand Down
16 changes: 7 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
A Markov Chain generator based on song lyrics.
Also mixes in text from the artist Wikipedia page
in order to give the sentences a better structure.
Adjust the weights using the option to play with the
relative amounts of material used in rendering the final model.
'''
_epilog='''
Best invoked like pipenv run python main.py, OR
Expand All @@ -29,7 +31,7 @@

# LyricsGenius API
TOKEN = environ.get('GENIUS_CLIENT_ACCESS_TOKEN')
EXCLUDE = ['(Demo)', '(Live)', 'Remix', 'Acoustic']
EXCLUDE = ['(Demo)', '(Live)', 'Remix', '(Mix)', 'Acoustic', 'Radio Edit', '(Edit)', '(Skit)', '(Instrumental)', '(Snippet)', '(Bootleg)']

# Wikipedia API
WIKI_LANG = 'en'
Expand Down Expand Up @@ -117,19 +119,13 @@ def get_model(model_name, config):

def main(config):
logging.info(config)

lyric_model = get_model(LYRIC_MODEL_NAME, config)
wiki_model = get_model(WIKI_MODEL_NAME, config)
logging.debug('{}={}, {}={}'.format(
'LYRICS model', type(lyric_model),
'WIKI model', type(wiki_model)
))

lyric_model_weight = 1
wiki_model_weight = 1.1

model = markovify.combine(
[lyric_model, wiki_model],
[lyric_model_weight, wiki_model_weight]
[config.lyric_weight, config.wiki_weight]
)

for _ in range(config.number):
Expand All @@ -142,6 +138,8 @@ def configure():
parser.add_argument('--wiki', '-w', required=True)
parser.add_argument('--songs', '-s', default=20, required=False, type=int)
parser.add_argument('--number', '-n', default=10, required=False, type=int)
parser.add_argument('--lyric-weight', '-p', default=1.0, required=False, type=float)
parser.add_argument('--wiki-weight', '-q', default=0.0, required=False, type=float)
return parser.parse_args()


Expand Down

0 comments on commit 944f765

Please sign in to comment.