Safetensors
English
bert
marcmaxmeister commited on
Commit
c7d72ed
·
verified ·
1 Parent(s): 972bf22

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +51 -1
README.md CHANGED
@@ -100,5 +100,55 @@ BERT Natural Language Outputs:
100
  (2) Classification probability for the designated religious affiliations (and classification probability)
101
  (3) Classification probability for whether the organisation is religious or not (and probability)
102
 
103
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
 
100
  (2) Classification probability for the designated religious affiliations (and classification probability)
101
  (3) Classification probability for whether the organisation is religious or not (and probability)
102
 
103
+ # 5\. Example usage
104
+
105
+ This is a minimal-code example of how to use the to classify texts as related to a religion (or none)
106
+ This model is public and doesn't require login to download. Use `snapshot_download` to get the full model, latest version.
107
+ ```
108
+ repo_id = 'GivingTuesday/religious_org_v1'
109
+ from huggingface_hub import snapshot_download
110
+ snapshot_download(repo_id)
111
+
112
+ # snapshot_download will return / print a location for the model. Pass that into the function below.
113
+ from transformers import pipeline
114
+ # 1. Define the local path to your downloaded model directory
115
+ # Replace './my_local_model_directory' with the actual path on your machine
116
+ model_path = './my_local_model_directory' # copied from output of previous cell
117
+
118
+ # 2. Load the text classification pipeline from the local directory
119
+ # The 'pipeline' function automatically loads the model, tokenizer, and config
120
+ # from the specified local path.
121
+ try:
122
+ classifier = pipeline(
123
+ task="text-classification",
124
+ model=model_path,
125
+ tokenizer=model_path
126
+ )
127
+ print(f"Model loaded successfully from {model_path}")
128
+ except Exception as e:
129
+ print(f"Error loading model: {e}")
130
+ print("Please ensure the directory contains the model weights, config, and tokenizer files.")
131
+ exit()
132
+
133
+ # 3. Define the string(s) you want to classify
134
+ sentences = [
135
+ """St. John's Episcopal is a really beautiful community that preaches "faith in action" -- they welcome and assist migrants, partner with community organizations, run a housing first apartment building for unhoused folks, and they are part of the Together Colorado coalition of faith-based organizations that lobbies for anti-poverty legislation. Bonus: the cathedral is gorgeous and historic.""",
136
+ """I’m atheist but rehearse in a community choir at Christ Church United Methodist and they have pro LGBTQ+ stuff everywhere. They even do a reconciliation Sunday service every year in June during pride month""",
137
+ ]
138
+
139
+ # 4. Run the classification on the input string(s)
140
+ results = classifier(sentences)
141
+
142
+ # 5. Print the results
143
+ for i, result in enumerate(results):
144
+ print(f"\nText: '{sentences[i]}'")
145
+ print(f"Classification Results:")
146
+ # Results can be a list of dictionaries if top_k is used
147
+ if isinstance(result, list):
148
+ for label_info in result:
149
+ print(f"- Label: {label_info['label']}, Score: {label_info['score']:.4f}")
150
+ else:
151
+ print(f"- Label: {result['label']}, Score: {result['score']:.4f}")
152
+
153
+ ```
154