avatarErnio Hernandez

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2504

Abstract

Training</b>: Train the model on your dataset, adjusting the weights of the pre-trained model minimally to fit the new task.</li></ol><h1 id="2b3a">Implementation in Python Using Hugging Face</h1><p id="1209">Here’s a step-by-step guide to implementing transfer learning with Hugging Face’s Transformers library.</p><h2 id="cd98">1. Install Required Libraries</h2><div id="ef5f"><pre>pip install transformers datasets</pre></div><h2 id="0f8c">2. Load a Pre-trained Model</h2><p id="df2e">First, choose a pre-trained model. For example, we’ll use BERT for a text classification task.</p><div id="2de3"><pre><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BertTokenizer, BertForSequenceClassification

<span class="hljs-comment"># Load the tokenizer and model</span> tokenizer = BertTokenizer.from_pretrained(<span class="hljs-string">'bert-base-uncased'</span>) model = BertForSequenceClassification.from_pretrained(<span class="hljs-string">'bert-base-uncased'</span>, num_labels=<span class="hljs-number">2</span>)</pre></div><h2 id="5e2d">3. Prepare Your Dataset</h2><p id="e504">You can use the <code>datasets</code> library from Hugging Face to load and prepare your dataset.</p><div id="b27c"><pre><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-comment"># Load a dataset (e.g., the IMDb movie reviews dataset)</span> dataset = load_dataset(<span class="hljs-string">'imdb'</span>) <span class="hljs-comment"># Tokenize the dataset</span> <span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_function</span>(<span class="hljs-params">examples</span>): <span class="hljs-keyword">return</span> tokenizer(examples[<span class="hljs-string">'text'</span>], padding=<span class="hljs-string">"max_length"</span>, truncation=<span class="hljs-literal">True</span>) tokenized_datasets = dataset.<span class="hljs-built_in">map</span>(tokenize_function, batched=<span class="hljs-literal">True</span>)</pre></div><h2 id="7357">4. Fine-Tune the Model</h2><p id="1060">Fine-tuning involves training the model on your specific dataset. You can use the <code>Trainer</code> API from Hugging Face to simplify this process.</p><div id="0069"><pre><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer, TrainingArguments

<span class="hljs-comment"># Define training arguments</span> training_args = TrainingArgumen

Options

ts( output_dir=<span class="hljs-string">'./results'</span>, evaluation_strategy=<span class="hljs-string">"epoch"</span>, per_device_train_batch_size=<span class="hljs-number">8</span>, per_device_eval_batch_size=<span class="hljs-number">8</span>, num_train_epochs=<span class="hljs-number">3</span>, weight_decay=<span class="hljs-number">0.01</span>, ) <span class="hljs-comment"># Define the Trainer</span> trainer = Trainer( model=model, args=training_args, train_dataset=tokenized_datasets[<span class="hljs-string">'train'</span>], eval_dataset=tokenized_datasets[<span class="hljs-string">'test'</span>], ) <span class="hljs-comment"># Train the model</span> trainer.train()</pre></div><h2 id="c70a">5. Evaluate the Model</h2><p id="39aa">After training, evaluate the model to see how well it performs on the test set.</p><div id="f7a4"><pre><span class="hljs-comment"># Evaluate the model</span> eval_results = trainer.evaluate() <span class="hljs-built_in">print</span>(<span class="hljs-string">f"Evaluation results: <span class="hljs-subst">{eval_results}</span>"</span>)</pre></div><h2 id="e3a9">6. Save the Fine-Tuned Model</h2><p id="1121">Finally, save the fine-tuned model for future use.</p><div id="297e"><pre><span class="hljs-comment"># Save the model and tokenizer</span> model.save_pretrained(<span class="hljs-string">"./fine-tuned-bert"</span>) tokenizer.save_pretrained(<span class="hljs-string">"./fine-tuned-bert"</span>)</pre></div><h1 id="254a">Additional Tips</h1><ul><li><b>Leverage Hugging Face’s community:</b> Explore pre-trained models and datasets shared by others.</li><li><b>Experiment with different architectures:</b> Try different model architectures to find the best fit.</li><li><b>Regularization:</b> Use techniques like dropout or L1/L2 regularization to prevent overfitting.</li><li><b>Data augmentation:</b> Increase data diversity by applying transformations to your dataset.</li></ul><h1 id="30b5">Conclusion</h1><p id="559f"><b>Transfer learning</b> with <b>Hugging Face</b> is a powerful technique to accelerate model development and improve performance, especially for <b>NLP</b> tasks. By leveraging pre-trained models and fine-tuning them on specific tasks, you can achieve high accuracy with minimal training time and resources. Hugging Face’s <b>Transformers </b>library makes this process straightforward, providing tools and pre-trained models that are easy to adapt to various tasks.</p></article></body>

My Condolences

A short play by Ernio Hernandez

A funeral home. Some time in the afternoon or early evening.

(MIRIAM and WALTER enter and take seats at center with Walter on the aisle.)

MIRIAM. Do you see our flowers? You sent the flowers right?

WALTER. I sent an arrangement, maybe it’s in the back, it’s still early.

MIRIAM. I don’t like coming to these things; I don’t know the protocols.

WALTER. You come in, say “My condolences,” say hello to the people you know, couple of “Such a shame”s. And you go.

MIRIAM. Isn’t there usually a priest or eulogy?

WALTER. I think that’s tomorrow at the burial. This is just the wake.

MIRIAM. I thought this was going to start at 7.

WALTER. I told you we’re early. I don’t know why you insist on going to everything early. Nobody does that anymore.

MIRIAM. People do that.

WALTER. You do that.

MIRIAM. Don’t start with me here. This is neither the time nor the place.

WALTER. Who’s starting anything?

MIRIAM. I’m just saying.

WALTER. Is that Louisa over there? I don’t see anybody I know.

MIRIAM. Maybe if we attended more family functions we might know more people at these things.

WALTER. Are you saying you want to go to more family functions just so we have people to talk to when someone dies?

MIRIAM. That is not what I’m saying. But isn’t that what these things end up being anyway, people talking about anything BUT the elephant in the room?

WALTER. I suppose so. Such a shame.

MIRIAM. Did you bring Maureen’s casserole dish she lent us last week?

WALTER. I was supposed to bring a casserole dish here?

MIRIAM. I’m saying: she’s probably going to be here. We tell her we have it in the car for her. She can come out and get it if she wants.

WALTER. I don’t think she expects us to bring it here,

MIRIAM. Oh now you’re the expert on Maureen?

WALTER. Now who’s starting?

MIRIAM. Alright, alright. Did you take a prayer card?

WALTER. What do I want with that?

MIRIAM. You take a prayer card; they print them up for a reason.

WALTER. Do you want me to get you a prayer card?

MIRIAM. No, don’t go get one now, it’ll be obvious you didn’t take one.

WALTER. I could just be going to the bathroom. You know, I’m not entirely a moron.

MIRIAM. No one said you were.

WALTER. Well you’re acting like I am.

MIRIAM. I’m just nervous, I told you; I don’t know what you do at these things.

WALTER. This is it. Pretty much all you do.

MIRIAM. Do we have to go up there?

WALTER. If you want, it’s not a procedure; no one’s grading you on your pomp and circumstance.

MIRIAM. What? You don’t even know what that means.

WALTER. What?

MIRIAM. Pomp and circumstance.

WALTER. Yes I do.

MIRIAM. Sure you do. You’re the brains of this operation.

WALTER. Okay, now you’re not calling me a moron?

MIRIAM. Alright, alright, I’m sorry. Keep your voice down.

WALTER. Okay, I’m going to get you a prayer card.

MIRIAM. Not yet, not yet. Okay do it slowly and make sure you sign the guest book.

WALTER. Now I gotta sign a guest book too?

MIRIAM. I don’t know when you’re supposed to do that, just look at it as you go by, see if other people signed it.

WALTER. Anything else, your highness?

MIRIAM. Don’t be snide. And hurry back. I don’t want to be left alone here too long.

(WALTER exits. MIRIAM waits a moment, looks around. She looks up toward the coffin and around again. Stands up slowly and walks downstage toward the coffin. She looks at the picture atop the coffin and leans over closer to see it. She looks confused. Then, she realizes she’s in the wrong room. WANDA enters and walks up to Miriam.)

WANDA. Hello. Thank you for being here. I’m Betty’s sister Wanda. You look familiar but I can’t place you, not that I knew anything my sister was up to or who she hung out with. In fact, don’t tell anybody, but I honestly don’t know half the people who are here. I only just flew in yesterday from the far reaches of Greenland. I’ve been doing a climate research project up there in the frozen tundra, you might say. It’s all rather bleak and bare and I don’t get to talk to people much. I actually had to get the news of my sister’s passing from one of our liaisons who is based some hundreds of miles away at our sister location. They have the satellite connection there. The poor fellow, he had to spend his entire day getting to me, be the bearer of bad news and then turn back around. I’m sure to only to make the same trip with my replacement for the weekend. Wonderful fellow though, rather large, there’s something about getting discomforting news from such an immense being. I think he felt the need to console me, maybe with a hug, which might have been a wonderful feeling but as you can imagine he was rather bundled up. And well, scientists aren’t notoriously known for their comfort with physical touch. I believe he’s Inuit, but I’m not sure that’s true. I don’t really know enough about their people or customs to know if contact of that kind is even taboo or something. I could really go for a drink right now and I don’t mean like a stiff one, I’m just very, very thirsty. I wonder if it’s the change in temperature, my body may just be acclimating itself. I’m so sorry to do this but I must get some water. So lovely to meet you.

MIRIAM. I’m so sorry… for your loss. My condolences. Such a shame.

(WANDA exits. MIRIAM returns to her seat. WALTER returns and sits alongside Miriam.)

WALTER. Who was that?

MIRIAM. I don’t know.

WALTER. Here’s your prayer card.

MIRIAM. Walter…

WALTER. Yes, I signed the guest book too. There were a dozen or so names already on it.

MIRIAM. Walter…

WALTER. I didn’t seem to recognize ANY of the names; my eyes must be going.

MIRIAM. WALTER!

WALTER. What? What did I forget now?

MIRIAM. We’re in the wrong room.

WALTER. We’re what?

MIRIAM. This is not Andrea’s viewing.

WALTER. Whattadaya mean, this isn’t Andrea’s… Look at the prayer card right there: In Loving Memory: Betty… Betty? Oh no.

MIRIAM. I know, I know. What are we gonna do?

WALTER. Well, I’ve already used my break to the bathroom.

MIRIAM. I told you to wait.

WALTER. You told me to go.

MIRIAM. Alright, alright.

WALTER. Let’s just go.

MIRIAM. Yeah?

WALTER. Yeah, we’re never going to see any of these people again.

MIRIAM. Noooo. I’m afraid I’ll run into that girl.

WALTER. Well, what do you want to do?

MIRIAM. I dunno. Let’s just sit here for a minute.

WALTER. Give me your hand.

MIRIAM. Why?

WALTER. Miriam, life’s too short to sit around worrying about what other people think. I’m taking you home.

MIRIAM. I dunno, Walter.

WALTER. Come on, we’ve got a casserole dish to return.

MIRIAM. Okay.

(MIRIAM grabs Walter’s hand and stands to leave.)

WALTER. And maybe on the way back, we’ll stop and get some ice cream.

MIRIAM. Look who’s all Mr. Romance now.

WALTER. Death brings out the best in me. Like you.

MIRIAM. So I’m like death?

WALTER. (sighs) Yes, Miriam. Let’s go.

(MIRIAM and WALTER exit.)

END

My Condolences by Ernio Hernandez

Copyright ©2009 | Ernio Hernandez | All Rights Reserved. (For permission to perform, contact author at ernio @ ernio.com)

Ernio Hernandez is a writer of plays, poems, short stories, essays, humor and other flights of fancy.

Other plays: Translation by | One Swipe Left | The Last Call | The Middle of Things | Ajar, by the Door

Fiction
Humor
Love
Comedy
Relationships
Recommended from ReadMedium